Linux网络配置(/etc/network/interfaces)
设置网络接口
主要的网络配置工作都可以通过/etc/network/interfaces文件进行,例如设置网卡IP地址(或使用dhcp)、 设置路由信息、配置IP掩蔽、设置默认路由等等。
开启和关闭接口
网络接口可以通过ifup和ifdown命令进行开启和关闭
重启启动网络服务并不能应用所有/etc/network/interfaces的更改,应该使用ifup和ifdown命令应用对接口的修改,以enp7s0网口为例:
$ ifdown enp7s0
$ ifup enp7s0
重新初始化网络配置
如果你修改了很多网络配置,例如在/etc/network/interfaces
添加一个新的虚拟网络接口,你可以通过重启网络配置守护进程networking
来重新初始化网络配置
$ systemctl status networking
$ systemctl restart networking
配置网口为DHCP模式
以debian系统为例,/etc/network/interfaces
文件默认内容为
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
配置网口为STATIC模式
配置网口为IPv4静态地址,可以按照添加如下内容(network、broadcast和gateway是可选的)
auto eth0
iface eth0 inet static
address 192.0.2.7/24
gateway 192.0.2.254