Debian 4.9 Config Static Ip.md

Linux debian 4.9.0-6-amd64 #1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02) x86_64

kk@debian:~$ cat /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

修改后

# 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 enp0s3
iface lo inet loopback

iface enp0s3 inet static
        address 192.168.20.103
        netmask 255.255.255.0
        gateway 192.168.20.1
dns-nameservers 114.114.114.114

kk@debian:~$ /sbin/ifconfig

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.20.103  netmask 255.255.255.0  broadcast 192.168.20.255
        inet6 fe80::a00:27ff:fe30:e855  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:30:e8:55  txqueuelen 1000  (Ethernet)
        RX packets 87  bytes 8538 (8.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 155  bytes 21027 (20.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

重启网络服务

sudo /etc/init.d/networking restart

这样修改之后, 内网可以 ssh 登陆虚拟机, 但是虚拟机无法连接外网.

修改方案:

sudo vim /etc/resolv.conf

默认该文件是空, 添加如下行:

nameserver 114.114.114.114

重启网络服务

sudo /etc/init.d/networking restart