1. 程式人生 > >Debain系統修改IP地址步驟

Debain系統修改IP地址步驟

1.修改 etc/network 下的 interfaces 檔案
/etc/network# cat interfaces
原來的內容為:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

註釋掉原來的配置資訊:

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
# source-directory /etc/network/interfaces.d
#
# allow-hotplug eth0
# iface eth0 inet dhcp
#
# allow-hotplug wlan0
# iface wlan0 inet dhcp
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

修改ip的獲取方式為靜態繫結ip,在上邊的基礎上新增配置資訊:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
# source-directory /etc/network/interfaces.d
#
# allow-hotplug eth0
# iface eth0 inet dhcp
#
# allow-hotplug wlan0
# iface wlan0 inet dhcp
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.0.200.242
netmask 255.255.255.0
gateway 10.0.200.1
broadcast 10.0.200.255

2.修改 /etc/resolv.conf ,其中可能有多個servername屬性,更改最邊的servername為閘道器地址(gateway).
nameserver 10.0.200.1
nameserver xxx.xxx.xxx.xxx
nameserver yyy.yyy.yyy.yyy

3.重啟網路
/etc/init.d/networking restart

4.繫結arp表
使用dhcp方式獲取的ip,會自動在arp中生成對應的路由資訊,如果手動繫結ip地址,需要手動在arp中將該機器的mac地址和ip進行繫結,否則不能訪問外網。即使可以ping通。