Debian/Ubuntu更换网卡换IP完美解决方案

第一步:修改网卡信息

 

修改文件/etc/udev/rules.d/z25_persistent-net.rules 文件,原来为:

protime-linux:/etc/udev/rules.d# cat z25_persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, probably run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.
# MAC addresses must be written in lowercase.
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM==”net”, DRIVERS==”?*”, ATTRS{address}==”00:0c:29:15:3a:48″, NAME=”eth0″
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM==”net”, DRIVERS==”?*”, ATTRS{address}==”00:0c:29:15:3a:52″, NAME=”eth1″
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM==”net”, DRIVERS==”?*”, ATTRS{address}==”00:0c:29:af:1c:c7″, NAME=”eth2″

修改后:

protime-linux:/etc/udev/rules.d# cat z25_persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, probably run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.
# MAC addresses must be written in lowercase.
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM==”net”, DRIVERS==”?*”, ATTRS{address}==”00:0c:29:15:3a:48″, NAME=”eth2″
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM==”net”, DRIVERS==”?*”, ATTRS{address}==”00:0c:29:15:3a:52″, NAME=”eth1″
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM==”net”, DRIVERS==”?*”, ATTRS{address}==”00:0c:29:af:1c:c7″, NAME=”eth0″

保存重启后可以看到原来的网络配置又回来了。
第二部:修改IP
debian的IP地址信息的文件是保存在/etc/network/interfaces,直接编辑该文件就可以。

#可以看到文件中的设置为动态IP的语句
iface eth0 inet dhcp

当然也可以设置为静态IP地址,如:

在 /etc/network/interfaces 中,删除 iface eth0 inet dhcp,添加一下内容

iface eth0 inet static
address 172.17.10.40
netmask 255.255.0.0
broadcast 172.17.0.255
network 172.17.0.0
gateway 172.17.10.100

重启网络
#/etc/init.d/networking restart

 

Leave a Reply

Your email address will not be published.