Linux下/etc/network/interfaces文件用來配置網(wǎng)絡(luò)接口。
初始化網(wǎng)口Ethernet Interface
大部分的網(wǎng)絡(luò)接口配置都可以在/etc/network/interfaces中解決。例如為網(wǎng)卡配置靜態(tài)IP(dhcp),設(shè)置路由信息,配置IP掩碼,設(shè)置默認(rèn)路由等。
PS: 如果想要在系統(tǒng)啟動(dòng)時(shí)就自動(dòng)啟動(dòng)網(wǎng)口,需要添加auto一行,詳見下面示例。
1. 使用動(dòng)態(tài)IP地址
auto eth0
iface eth0 inet dhcp
2. 使用靜態(tài)IP地址
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
# network 192.168.1.0
# broadcast 192.168.1.255
network和broadcast一般使用默認(rèn)值就行。
3. 查看路由表
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
route -n不解析名字。
以上就是腳本之家小編給大家整理的相關(guān)內(nèi)容,感謝大家的學(xué)習(xí)和支持。