首先说下问题产生场景:最近搞jenkins搭建持续集成,搞完后发现服务器ip(ifconfig 红色)老是变化,一怒之下果断修改ip
[root@bogon etc]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:F4:A4:5A inet addr:192.168.229.129 Bcast:192.168.229.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fef4:a45a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:544599 errors:0 dropped:0 overruns:0 frame:0 TX packets:230155 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:661731467 (631.0 MiB) TX bytes:54607105 (52.0 MiB) Interrupt:19 Base address:0x2024lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:15743 errors:0 dropped:0 overruns:0 frame:0 TX packets:15743 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:67040869 (63.9 MiB) TX bytes:67040869 (63.9 MiB)
改完ping 了下github.com 和百度外网一直显示unknown host
[root@bogon etc]# ping www.baidu.com
ping: unknown host www.baidu.com我就纳闷了找找博客看了一圈整理下思路:
问题分析过程如下:
首先检查windows 网络中心配置尤其是v8的:
cmd检查也可以:主要看网关和虚拟机在不在一个网段,ip windows不可以和虚拟机的ifconfig ip相同但要在一个网段
虚拟机网关查看centos6如下:
虚拟机网关查看:注意这个网关必须和windows v8适配器网关保持一致
以上如果出现不一致应该修改保持一致:windows修改在
此外虚拟机修改如下文件见标红,这个地方网关必须和虚拟机网卡v8网关一致,ip设置成你要的固定ip但是要和windows 适配器v8在同网段不同ip,DNS1填这个谷歌的就可以:
[root@bogon etc]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"BOOTPROTO=staticIPADDR=192.168.229.129GATEWAY=192.168.229.2NETMASK=255.255.255.0HWADDR="00:0C:29:F4:A4:5A"IPV6INIT="yes"NM_CONTROLLED="yes"ONBOOT="yes"TYPE="Ethernet"UUID="32f46724-9e38-4712-b088-29be2ae53bc4"DNS1=8.8.8.8设置永久默认网关添加GATEWAY
[root@bogon sysconfig]# vi /etc/sysconf/network
NETWORKING=yesHOSTNAME=bogonGATEWAY=192.168.229.2
然后重启网络适配器:service network restart
检查route 路由网关:route
[root@bogon etc]# route ,default 开头是默认网关Gateway
Kernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.229.0 * 255.255.255.0 U 1 0 0 eth0default bogon 0.0.0.0 UG 0 0 0 eth0ping www.baidu.com 检查如下成功:
[root@bogon etc]# ping www.baidu.com
PING www.a.shifen.com (163.177.151.110) 56(84) bytes of data.64 bytes from 163.177.151.110: icmp_seq=1 ttl=128 time=11.1 ms64 bytes from 163.177.151.110: icmp_seq=2 ttl=128 time=10.5 ms64 bytes from 163.177.151.110: icmp_seq=3 ttl=128 time=11.0 ms注意如果你centos7 不是6修改完网卡后要重启网卡比如centos7 的ens33网卡:
[root@hostuser network-scripts]# ifdown ens33
成功断开设备 'ens33'。[root@hostuser network-scripts]# [root@hostuser network-scripts]# ifup ens33连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/5)验证修改效果
[root@hostuser network-scripts]# route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.81.2 0.0.0.0 UG 100 0 0 ens33192.168.81.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0[root@hostuser network-scripts]#