修改网卡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)
补充:静态网卡配置信息:
原文地址:http://blog.csdn.net/siyanyanyanyai/article/details/25509357