如何在 Ubuntu 16.04 上的 OVH VPS 中将 DHCP 接口更改为静态接口

How to change a DHCP interfaces to STATIC interfaces in OVH VPS on Ubuntu 16.04

我是 LINUX 的新手,我需要你帮助我的 OVH VPS Ubuntu 服务器 16.04LTS 接口实际上在 DHCP 到静态

实际上我的 /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

# Source interfaces
# Please check /etc/network/interfaces.d before changing this file
# as interfaces may have been defined in /etc/network/interfaces.d
# See LP: #1262951
source /etc/network/interfaces.d/*.cfg

源路径/etc/network/interfaces.d/*.cfg 只有一个文件名为:50-cloud-init.cfg 并且该文件包含:

auto lo
iface lo inet loopback

auto ens3
iface ens3 inet dhcp

所以我的 IP 地址是 149.xxx.xxx.61,我需要将其转换为我的 IP 地址的静态 iface ens3。

实际上 ifconfig -a 是:

ens3      Link encap:Ethernet  HWaddr fa:16:3e:ae:e3:83  
          inet addr:149.xxx.xxx.61  Bcast:149.xxx.xxx.61  Mask:255.255.255.255
          inet6 addr: fe80::xxxx:xxxx:feae:e383/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:894526 errors:0 dropped:0 overruns:0 frame:0
          TX packets:297070 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:102187906 (102.1 MB)  TX bytes:63602471 (63.6 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:14743 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14743 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:31459525 (31.4 MB)  TX bytes:31459525 (31.4 MB)

我该怎么做?

这是一个示例文件,其中包含来自我的一台服务器的指南:

请注意:并非所有 OVH 服务器都支持 IPv6 或路由 IPv6 地址。您可以在您的控制面板中检查此项,如果您没有看到要使用的地址或不希望 IPv6 支持,请不要包括该部分。 要找到路由 IPv6 所需的 link 本地地址,可以通过 OVH API or by converting the interface's MAC address into an appropriate link-local address.

当然,如果您没有任何故障转移 IP 地址,请不要包含该部分。

最后,请注意,在某些基于 VMware 的虚拟机上,网关的最后一个八位字节可能需要 .254 而不是 .1

auto lo
iface lo inet loopback

#auto ens3
#iface ens3 inet dhcp

#--static IPv4--
auto ens3
iface ens3 inet static
        address <main server IP>
        netmask 255.255.255.255
        broadcast <main server IP>
        gateway <main server IP's first three octets>.1
        dns-nameservers 8.8.8.8 8.8.4.4

#iface ens3 inet6 dhcp #does not seem to work for OVH VPS 2016 range

#--static IPv6--
iface ens3 inet6 static
        address <IPv6 address-should begin with 2001:41d0:>
        netmask 128
        post-up /sbin/ip -6 route add <IPv6 link local-should begin with fe80::> dev ens3
        post-up /sbin/ip -6 route add default via <IPv6 link local-should begin with fe80::> dev ens3
        pre-down /sbin/ip -6 route del default via <IPv6 link local-should begin with fe80::> dev ens3
        pre-down /sbin/ip -6 route del <IPv6 link local-should begin with fe80::> dev ens3
        dns-nameservers 2001:4860:4860::8888 2001:4860:4860::8844

#--failover IP address #1--
auto ens3:0
iface ens3:0 inet static
        address <failover IP address #1>
        netmask 255.255.255.255
        broadcast <failover IP address #1>

#--failover IP address #2--
auto ens3:1
iface ens3:1 inet static
        address <failover IP address #2>
        netmask 255.255.255.255
        broadcast <failover IP address #2>

首先,您必须找到 IPv6 的 IP 和网关。它们可以在您的 OVH 管理器中找到。

使用此命令修改您的网络配置文件(如果您不是 root,请使用 sudo):

nano /etc/network/interfaces.d/50-cloud-init.cfg

添加这些行:

iface eth0 inet6 static
    address YOUR_IPV6
    netmask IPV6_PREFIX
    post-up /sbin/ip -f inet6 route add IPV6_GATEWAY dev eth0
    post-up /sbin/ip -f inet6 route add default via IPV6_GATEWAY
    pre-down /sbin/ip -f inet6 route del IPV6_GATEWAY dev eth0
    pre-down /sbin/ip -f inet6 route del default via IPV6_GATEWAY

YOUR_IPV6 必须替换为您的 IPv6。 IPV6_PREFIX 必须替换为 128。 IPV6_GATEWAY 必须替换为您的 IPv6 网关。

重新启动您的 VPS。

参考:http://docs.ovh.ca/fr/guides-network-ipv6.html#debian-derivatives-ubuntu-crunchbang-steamos