由于某些原因,在虚拟机里做测试,需要固定IP,故而把这个流程记录下来。
1.首先获取你的GATEWAY,方便后面在cento系统配置里使用
选取菜单栏:Edit->Virtual Network Editor
选择VMnet8,点击NAT Settings查看一下GATEWAY地址:此处的Gateway IP 为 192.168.110.2
接下来就可以进入正题了。
2.设置CentOS静态IP:
涉及到三个配置文件,分别是:
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/resolv.conf
a.首先修改/etc/sysconfig/network如下:
指定网关地址。
b.然后修改/etc/sysconfig/network-scripts/ifcfg-eth0:
- DEVICE="eth0"
- #BOOTPROTO="dhcp"
- BOOTPROTO="static"
- IPADDR=192.168.110.129
- NETMASK=255.255.255.0
- HWADDR="00:0C:29:53:A8:1D"
- IPV6INIT="no"
- NM_CONTROLLED="yes"
- ONBOOT="yes"
- TYPE="Ethernet"
- UUID="f933b2bf-47eb-42f3-bea9-1f54088a2cb7"
- DNS1=192.168.110.2
c.最后配置下/etc/resolv.conf:(其实这一步可以省掉,上面设置了DNS Server的地址后系统会自动修改这个配置文件。)
- # Generated by NetworkManager
- nameserver 192.168.110.2
这样很简单几个步骤后虚拟机的IP就一直是192.168.110.129了。
固定好IP后,接下来就可以设置host
若出现centos下错误提示:Bringing up interface eth1: Error: No suitable device found: no device found for connection 'System eth1'.
1
2
3
4
5
6
|
[root@centos network-scripts] # /etc/init.d/network restart Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth1: Error: No suitable device found: no device found for connection 'System eth1' . [FAILED] [root@centos network-scripts] # |
解决方法:
用ifconfig -a查看显示的是eth1,但是在/etc/system/network-scripts/目录下面显示的是eth0,所以才会导致这个问题的出现,解决方法就是在目录中将eth0重命名为eth1,如果是虚拟机还要修改网卡地址.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@centos network-scripts] # ifconfig -a eth1 Link encap:Ethernet HWaddr 08:00:27:5C:4A:F6 inet addr:2.2.2.177 Bcast:2.2.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe5c:4af6 /64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:72479 errors:0 dropped:0 overruns:0 frame:0 TX packets:36533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:5311979 (5.0 MiB) TX bytes:26144482 (24.9 MiB) [root@centos network-scripts] # cp -a ifcfg-eth0 ifcfg-eth1 [root@centos network-scripts] # vim /etc/udev/rules.d/70-persistent-net.rules --查看网卡地址 [root@centos network-scripts] # rm -rf ifcfg-eth0 --如果是虚拟机还要修改网卡的地址 [root@centos ~] # /etc/init.d/network restart --重启成功了 Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth1: Active connection state: activated Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1 [ OK ] [root@centos ~] # |