Debian系列网卡配置详解

Posted surplus

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Debian系列网卡配置详解相关的知识,希望对你有一定的参考价值。

Debian系列的网卡配置和RH系列的不一样,这里说一下。 配置文件是/etc/network/interfaces,不管有多少网卡,只有这一个配置文件。

1.基本配置

auto lo     #开机启动loopback网卡
iface lo inet loopback  #网卡名称是lo, 类型是loopback

auto eth0
iface eth0 inet static
address 192.168.0.129
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1

2.更复杂的应用,包括添加和删除路由。up就是当这个网卡启用时,反之是down。

up route add -net 192.168.0.128 netmask 255.255.255.0 gw 192.168.0.2
up route add default gw 192.168.0.200
down route del default gw 192.168.0.200
down route del -net 192.168.0.128 netmask 255.255.255.0 gw 192.168.0.200

3.一个物理网卡上多个接口的配置方法。这种方法在配置一块网卡多个网址的时候很常见,有几个地址就配几个接口,冒号后面的数字是随意写的,只要不重复即可。

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
broadcast 192.168.0.255

4.pre-up和post-down命令时间。这是一组命令(pre-up/up/post-up/pre-down/down/post-down),分别定义在对应的时刻需要执行的命令。

auto eth0
iface eth0 inet dhcp
pre-up [ -f /etc/network/local-network-ok ]
# 这条命令的作用是在激活eth0之前检查该文件是否存在,如果不存在则不会激活网卡。

5.更复杂的例子

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
pre-up /path/to/check-mac-address.sh eth1 AA:BB:CC:DD:EE:FF
pre-up /usr/local/sbin/enable-masq

这个用法是为了避免两块网卡的识别顺序变化导致的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 lan
iface internet inet dhcp
pre-up /usr/local/sbin/firewall internet

上面的代码中所用到的脚本都在/usr/share/doc/ifdown/examples/目录下。

6.用一个网卡,但不对这个网卡设置任何IP,而是交由外部程序来设置它

auto eth0
iface eth0 inet manual
up ifconfig $IFACE 0.0.0.0 up
up /usr/local/bin/myconfigscript
down ifconfig $IFACE down

7.配置混杂模式,用作监听接口。

auto eth0
iface eth0 inet manual
up ifocnfig $IFACE 0.0.0.0 up
up ip link set $IFACE promisc on
down ip link set $IFACE promisc off
down ifconfig $IFACE down

8.配置无线网络接口

auto wlan0
iface wlan0 inet dhcp

以上是关于Debian系列网卡配置详解的主要内容,如果未能解决你的问题,请参考以下文章

Debian 双网卡配置

Debian怎么配置网卡(IP)

[01] Debian 10 配置多网卡绑定及VLAN接口

Debian双网卡配置

Debian 8 网卡手动配置

linux debian 网络配置方法