VPS 解析和静态 IP

VPS 解析和静态 IP

我有一个由国际知名的托管服务提供商托管的 vps 服务器,但奇怪的是,他们似乎无法对自己的系统进行故障排除。

有两个具体问题,可能相关,也可能不相关。

目前,我有一个 debian 10.5 vps 实例,它有 dhcp ip,(公共/私有 ip,尽管 dhcp 状态永远不会改变

问题:

我需要从 dhcp 切换到静态 ip,以便在主机上运行某些软件包。使用托管服务提供商提供的说明,我/etc/network/interfaces按如下方式配置了文件:

#The loopback network interface
auto lo
iface lo inet loopback

#The primary network interface
auto eth0
iface eth0 inet static
   address XXX.XX.XX.XXX
   netmask 255.255.255.0
   gateway XXX.XX.XX.XXX 

但是,重新启动后ip a仍然显示我的主网络接口 eth0 配置为“动态”而不是静态:

eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:xx:xx:01:XX:9d brd ff:ff:ff:ff:ff:ff
    inet xxx.xx.xx.xxx/18 brd xxx.xx.xx.xx scope global dynamic eth0   <---shows dynamic
       valid_lft xxxxxxxsec preferred_lft xxxxx4sec

此外,我的内容/etc/resolv.conf丢失的

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
options timeout:2 attempts:3 rotate single-request-reopen

有人知道到底出了什么问题吗?谢谢

注意:除了这些问题之外,其他一切似乎都运行良好。

答案1

经过 13 天的思考,我的托管服务提供商似乎找到了解决方案:

/etc/systemd/network/10-eth0.network文件必须进行如下编辑:

# nano /etc/systemd/network/10-eth0.network
[Match]
Name=eth0
[Network]
Address=xxx.XX.XX.XXX/18
Gateway=xxx.XX.XX.XX
DNS=xxx.xxx.x.xxx
DNS=xxx.xxx.x.xxx

/etc/network/interfaces 文件应进行如下编辑:

# nano /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static 
   address xxx.XX.XX.XX
   netmask 255.255.255.0
   gateway xxx.XX.XX.XXX
   dns-nameservers xxx.xxx.x.xx xxx.xxx.x.xxx

#ip a ,现在正确反映静态 IP:

eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:16:3e:01:78:9d brd ff:ff:ff:ff:ff:ff
    inet 172.17.51.140/18 brd 172.17.63.255 scope global eth0   <--- Static IP
       valid_lft forever preferred_lft forever

/etc/resolv.conf 包含:

# cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver xxx.xxx.x.xxx `<--dynamically added`
nameserver xxx.xxx.x.xxx `<--dynamically added`
options timeout:2 attempts:3 rotate single-request-reopen

现在“vps land”一切正常

相关内容