Change Network of Debian

语速

Sometimes we want to modify the default IP address and DNS server to achieve better network performance.

For Debian, modify two files: /etc/network/interfaces and /etc/resolv.conf.

Regarding interfaces:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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

# The primary network interface
allow-hotplug ens18
iface ens18 inet static
address 192.168.2.35
netmask 255.255.255.0
gateway 192.168.2.60

When the gateway is 192.168.2.60;

If DNS configuration is also needed, modify /etc/resolv.conf

1
nameserver 192.168.2.60

Disable IPv6

/etc/sysctl.conf

1
net.ipv6.conf.all.disable_ipv6 = 1

Don’t forget to restart the network: systemctl restart networking.