如何优雅地为Debian配置有线网络


Debian/Ubuntu自带的NetworkManager十分恶心,因此,有经验的用户往往希望扬掉这个垃圾,就像这样:

... basically I want to kill Network Manager and never see any trace of it again.

(from https://askubuntu.com/questions/249944/how-can-i-completely-remove-networkmanager)

这时,我们只需要卸载NetworkManager:

sudo apt-get purge network-manager

然后使用基本的ifupdown包来管理网络,这个是系统自带的,指令有ifupifdown两个。当然,我喜欢使用他的配置文件/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

# Network with DHCP enabled

auto <nic1>
allow-hotplug <nic1>
iface <nic1> inet dhcp

# Network which needs static IP configured

auto <nic2>
allow-hotplug <nic2>
iface <nic2> inet static
    address 10.0.0.2/24
    post-up ip route add 192.168.1.0/24 via 10.0.0.1
    post-down ip route del 192.168.1.0/24 via 10.0.0.1

基本的动态IP、静态IP配置方法可以照抄上面的配置文件,静态路由的设置也可以照抄。 配置完毕后,重启计算机即生效。