改动网卡IP信息的情况有非常多种,只是从大体上能够分为两种,一种是暂时改动,重新启动网络服务后改动便会失效;一种是永久改动,重新启动网络服务后才会生效。一般暂时改动应用在暂时的动作中,我们通过分类名字也能够知道,是为了应对下面暂时问题。而永久改动时为了构建一个稳定的网络环境,也就是所谓的生产环境。
如今我们分类介绍两种改动的简单操作。
一、暂时改动
更改前:
[root@desktop40 network-scripts]# ifconfig br0
br0 Link encap:Ethernet HWaddr 00:0C:29:4E:5B:F2 inet addr:192.168.1.131 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe4e:5bf2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:7300 errors:0 dropped:0 overruns:0 frame:0 TX packets:613 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:981381 (958.3 KiB) TX bytes:56311 (54.9 KiB)更改后:
[root@desktop40 network-scripts]# ifconfig br0 192.168.0.53 netmask 255.255.255.0 up
[root@desktop40 network-scripts]# ifconfig br0 br0 Link encap:Ethernet HWaddr 00:0C:29:4E:5B:F2 inet addr:192.168.0.53 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe4e:5bf2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:7390 errors:0 dropped:0 overruns:0 frame:0 TX packets:631 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:997607 (974.2 KiB) TX bytes:60847 (59.4 KiB)从上面的演示样例我们能够知道,我们的网卡IP暂时配置就是ifconfig、ifup、ifdown命令的使用,上面不过一个简单的样例,在改动IP时能够先将网卡ifdown,然后进行ifconfig的配置,配置完毕后再使用ifup命令启动网卡。在之文章開始我们已经讲过,暂时改动,在主机重新启动后会自己主动变回起始的參数配置。那么我们重新启动一下网络服务看一下是否如我们所说的一样呢。
[root@desktop40 network-scripts]# ifconfig br0
br0 Link encap:Ethernet HWaddr 00:0C:29:4E:5B:F2 inet addr:192.168.1.131 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe4e:5bf2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:7664 errors:0 dropped:0 overruns:0 frame:0 TX packets:669 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1043312 (1018.8 KiB) TX bytes:66993 (65.4 KiB)如我们所讲,网卡IP变回的初始配置。二、永久改动
我们知道要想永久的改动网络配置就要改动网络配置文件,在上一篇文章中我们已经将了网络配置文件的位置,这里就不做缀余了。
这是我的主机eth0的配置:
[root@desktop40 network-scripts]# cat ifcfg-eth0
DEVICE="eth0" BOOTPROTO="dhcp" HWADDR="00:0C:29:4E:5B:F2" IPV6INIT="yes" MTU="1500" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="a6c176f0-6f6c-4629-92b5-f13c577d37cd" DEVICE=eth0 BOOTPROTO=none BRIDGE=br0 ONBOOT=yes 这是我的主机br0的配置:[root@desktop40 network-scripts]# cat ifcfg-br0
# Bridge Networking Interface DEVICE=br0 ONBOOT=yes BOOTPROTO=dhcp TYPE=Bridge USERCTL=yes NM_CONTROLLED=no IPV6INIT=no PEERNTP=no DELAY=0 NAME="Bridge eth0" [root@desktop40 network-scripts]#从上面的配置我们能够知道我的网卡IP是动态的,那么我们就来将其配置成静态的。
原文件:
[root@desktop40 network-scripts]# vim ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="dhcp" HWADDR="00:0C:29:4E:5B:F2" IPV6INIT="yes" MTU="1500" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="a6c176f0-6f6c-4629-92b5-f13c577d37cd" DEVICE=eth0 BOOTPROTO=none BRIDGE=br0 ONBOOT=yes改动后:
[root@desktop40 network-scripts]# vim ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static" IPADDR=192.168.0.33 NETMASK=255.255.255.0 HWADDR="00:0C:29:4E:5B:F2" IPV6INIT="yes" MTU="1500" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="a6c176f0-6f6c-4629-92b5-f13c577d37cd" BRIDGE=br0完毕后继操作:
1、停掉NM
[root@desktop40 network-scripts]# service NetworkManager restart
Stopping NetworkManager daemon: [FAILED] Setting network parameters... [ OK ] Starting NetworkManager daemon: [ OK ] [root@desktop40 network-scripts]# service NetworkManager stop Stopping NetworkManager daemon: [ OK ]2、重新启动网络服务
[root@desktop40 network-scripts]# service network restart
Shutting down interface br0: [ OK ] Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: [ OK ] Bringing up interface br0: Determining IP information for br0... done. [ OK ]3、查看eth0网卡IP信息
[root@desktop40 network-scripts]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:0C:29:4E:5B:F2 inet addr:192.168.0.140 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe4e:5bf2/64 Scope:Link UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1 RX packets:9069 errors:0 dropped:0 overruns:0 frame:0 TX packets:971 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1348353 (1.2 MiB) TX bytes:106170 (103.6 KiB) 补充:静态网卡配置信息: