转自:http://blog.csdn.net/mountzf/article/details/52035499
===================================================
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.42
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
上面的配置中,
auto eth0
iface eth0 inet static
address 192.168.1.42
network 192.168.1.0
netmask 255.255.255.128
broadcast 192.168.1.0
up route add -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2
up route add default gw 192.168.1.200
down route del default gw 192.168.1.200
down route del -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2
这次,有了一个复杂一些的掩码,和一个比较奇怪的广播地址。还有就是增加的接口启用、禁用时的路由设置;
auto eth0 eth0:1
iface eth0 inet static
address 192.168.0.100
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
iface eth0:1 inet static
address 192.168.0.200
network 192.168.0.0
netmask 255.255.255.0
8行到11行在eth0上配置了另外一个地址,这种配置方法在配置一块网卡多个地址的时候很常见:有几个地址就配置几个接口。冒号后面的数字可以随便写的,只要几个配置的名字不重复就可以。
auto eth0
iface eth0 inet dhcp
pre-up [ -f /etc/local-network-ok ]
第3行会在激活eth0之前检查/etc/local-network-ok文件是否存在,如果不存在,则不会激活eth0。
auto eth0 eth1
iface eth0 inet static
address 192.168.42.1
netmask 255.255.255.0
pre-up /path/to/check-mac-address.sh eth0 11:22:33:44:55:66
pre-up /usr/local/sbin/enable-masq
iface eth1 inet dhcp
pre-up /path/to/check-mac-address.sh eth1 AA:BB:CC:DD:EE:FF
pre-up /usr/local/sbin/firewall
第5行和第8行中,check-mac-address.sh放在/usr/share/doc/ifupdown/examples/目录 中,使用的时候需要给它加上可执行权限。这两行命令会检测两块网卡的MAC地址是否为11:22:33:44:55:66和 AA:BB:CC:DD:EE:FF,如果正确,则启用网卡。如果MAC地址错误,就不会启用这两块网卡。
auto eth0 eth1
mapping eth0 eth1
script /path/to/get-mac-address.sh
map 11:22:33:44:55:66 lan
map AA:BB:CC:DD:EE:FF internet
iface lan inet static
address 192.168.42.1
netmask 255.255.255.0
pre-up /usr/local/sbin/enable-masq $IFACE
iface internet inet dhcp
pre-up /usr/local/sbin/firewall $IFACE
第3行中的get-mac-address.sh也在/usr/share/doc/ifupdown/examples/目录里,也同样要加可执行权限。这个脚本的作用,就是获得每块网卡的MAC地址。
auto eth0
iface eth0 inet manual
up ifconfig $IFACE 0.0.0.0 up
up /usr/local/bin/myconfigscript
down ifconfig $IFACE down
这段配置只是启用一个网卡,但是ifupdown不对这个网卡设置任何ip,而是由外部程序来设置ip。
最后一段配置,这段配置启用了网卡的混杂模式,用来当监听接口。auto eth0
iface eth0 inet manual
up ifconfig $IFACE 0.0.0.0 up
up ip link set $IFACE promisc on
down ip link set $IFACE promisc off
down ifconfig $IFACE down
好了,interfaces中对于以太网卡的配置基本上介绍完了
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 10.112.18.106
network 10.112.18.0
netmask 255.255.255.0
broadcast 10.112.18.255
gateway 10.112.18.254
dns-nameservers 10.112.18.1
就是最后一行dns-nameservers,可以添加多个,用空格分开。
查看网卡信息: ifconfigsu
设定一个网卡IP:ifconfig eth0 192.168.1.10 netmask 255.255.255.0查看路由相关信息:route -n
ifconfig 网卡名