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

posted on   剩余价值  阅读(10579)  评论(1编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示