Wave Spread...

Debian 9 配置多 IP 及 DNS 服务器

分类:Linux 评论: 0

新购入了一个 KVM 的云主机,并且自带两个IP,但是重新安装系统后系统只有一个IP,此文便为配置多个地址。

配置多 IP

查看当前网卡信息

root@domain:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
    link/ether 00:16:3c:d6:78:06 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.1/24 brd 216.126.238.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 2606:df00:3:0:216:3cff:fed6:7806/64 scope global mngtmpaddr dynamic 
       valid_lft 2591672sec preferred_lft 604472sec
    inet6 2607:fcd0:100:6a0b::17/64 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3cff:fed6:7806/64 scope link 
       valid_lft forever preferred_lft forever

修改网卡配置

使用 vi/vim 或者 nano 编辑网卡配置文件

root@domain:~# vim /etc/network/interfaces

以下为默认配置

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0                   #表示网卡随系统自动启动
iface eth0 inet static      #表示网卡为静态IP地址
 address 172.16.3.123       #IP地址
 netmask 255.255.255.0      #子网掩码
 gateway 172.16.3.1         #网关
 network 172.16.3.0
 broadcast 172.16.3.255

auto eth0:0
iface eth0:0 inet static
 address 10.16.3.123
 netmask 255.255.0.0
 network 10.16.0.0
 broadcast 10.16.255.255

如果使用DHCP,将iface eth0 inte static改为iface eth0 inet dhcp

配置 DNS 服务器

编辑DNS配置文件

root@domain:~# vim /etc/resolv.conf

添加以下字段

# IPv4 DNS
nameserver 8.8.8.8
nameserver 8.8.4.4
# IPv6 DNS
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

注意:需要重启机器或重启网卡才可生效!

重启网卡生效配置

root@domain:~# systemctl restart networking
回复