/etc/network/interfaces
是 debian 系统中最为重要的网络配置文件,它用于配置网络接口的参数。
介绍
- NAME /etc/network/interfaces - network interface configuration for
ifup
and ifdown
/etc/network/interfaces
文件用于指定如何配置网络接口- Debian 自带的网络管理的名字叫
ifupdown
- 该文件由 ifquery、ifup 和 ifdown 处理更改系统网络状态
安装
apt install ifupdown
- 详细配置信息
man interfaces
- /usr/share/doc/ifupdown/examples/network-interfaces.gz
- Starting and Stopping Interfaces
# ifdown enp7s0
# ifup enp7s0
- Reinitialize new network setup
# systemctl status networking
# systemctl restart networking
/etc/network/if-pre-up.d/
Scripts in this directory are run before bringing the interface up.
/etc/network/if-up.d/
Scripts in this directory are run after bringing the interface up.
/etc/network/if-down.d/
Scripts in this directory are run before bringing the interface down.
/etc/network/if-post-down.d/
Scripts in this directory are run after bringing the interface down.
常见配置
常规配置
auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.43.81
netmask 255.255.255.0
gateway 192.168.43.1
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
iface home inet static
address 192.168.43.80
netmask 255.255.255.0
gateway 192.168.43.1
说明:
auto lo
auto
用来识别以 -a
参数运行 ifup
时应该启用的物理接口(这一参数被用在系统启动脚本中)- 每条 `auto 接口 命令应占据一行,ifup 根据列出的顺序依次启用接口
allow-hotplug wlan0
allow-
用来识别应从各种子系统启用的接口ifup --allow=hotplug eth0 eth1
只会启用列在 allow-hotplug
行中的 eth0 或 eth1- 其中
allow-auto
和auto
是同义词
iface lo inet ...
、iface eth0 inet ...
、iface wlan0 inet ...
、iface default inet ...
iface
后是逻辑接口名。在最简单的情况下,如果不存在 mapping 配置,逻辑接口名与物理接口名相同。接口名后是接口所使用的地址族(address family)inet
是 TCP/IP v4inet6
是 IPv6
... inet loopback
、... inet static
、... inet manual
、... inet dhcp
inet
后是用来配置接口的方法loopback
方法用来定义 IPv4 loopback 接口static
方法定义接口的静态 IPv4 地址,包含的选项有 address、netmask、broadcast、metric、gateway、pointopoint、hwaddress、mtu、scopemanual
方法默认不配置接口,需通过外部程序(ifupdown 以外的程序)配置或手动配置dhcp
方法使用 dhclient
、pump
、udhcpc
、dhcpcd
中任意一个工具,通过 DHCP 获取 IP 地址
br 配置
auto br0
iface br0 inet static
address 10.10.0.15/24
gateway 10.10.0.1
bridge_ports eth0 eth1
up /usr/sbin/brctl stp br0 on
静态 IP 无线
auto wlan0
iface wlan0 inet static
address 192.168.3.186
netmask 255.255.255.0
gateway 192.168.3.1
wpa-ssid xxx
wpa-psk xxx
wpa-proto WPA
动态 IP 无线
auto wlan0
iface wlan0 inet dhcp
wpa-ssid xxx
wpa-psk xxx
wpa-proto WPA