简体   繁体   中英

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

Im new into LINUX and i need your help for my OVH VPS Ubuntu Server 16.04LTS interface actually on DHCP to STATIC

Actually my /etc/network/interfaces file is :

# 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

The source path /etc/network/interfaces.d/*.cfg have only one file named : 50-cloud-init.cfg and this file contain :

auto lo
iface lo inet loopback

auto ens3
iface ens3 inet dhcp

So my IP address is 149.xxx.xxx.61, I need to transform this to have an iface ens3 static for my IP address.

Actually ifconfig -a is :

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)

How can I do this ?

Here is an example file with a guide from one of my servers:

Please note: not all OVH servers have IPv6 support or a routed IPv6 address. You can check this in your control panel and if you do not see an address to use or don't want IPv6 support do not include that section. To find your link local address required for routing the IPv6 it can be found via the OVH API or by converting the interface's MAC address into an appropriate link-local address.

And of course, if you do not have any failover IP addresses do not include that section.

And last, please note that on some VMware based VMs the gateway's last octet may need to be .254 instead of .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>

First, you must find your IP and Gateway for IPv6. They can be found in your OVH manager.

Modify your network config file with this command (use sudo if you are not root) :

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

Add these lines :

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 must be replaced with your IPv6. IPV6_PREFIX must be replaced with 128. IPV6_GATEWAY must be replaced with your IPv6 gateway.

Reboot your VPS.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM