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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM