Linux下/etc/network/interfaces文件用來配置網絡接口。
初始化網口Ethernet Interface
大部分的網絡接口配置都可以在/etc/network/interfaces中解決。例如為網卡配置靜態IP(dhcp),設置路由信息,配置IP掩碼,設置默認路由等。
PS: 如果想要在系統啟動時就自動啟動網口,需要添加auto一行,詳見下面示例。
1. 使用動態IP地址
auto eth0
iface eth0 inet dhcp
2. 使用靜態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一般使用默認值就行。
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不解析名字。
以上就是腳本之家小編給大家整理的相關內容,感謝大家的學習和支持。