Default /etc/network/interfaces in Ubuntu 18.04 in OVH VPS look like following. Click here for Ubuntu 20.04 instructions.
root@vps624512:~# cat /etc/network/interfaces # ifupdown has been replaced by netplan(5) on this system. See # /etc/netplan for current configuration. # To re-enable ifupdown on this system, you can run: # sudo apt install ifupdown root@vps624512:~#
First install
sudo apt install ifupdown -y
Configure Main IP
use “ip a” command to find out interface name and IP of the VPS
root@vps624512:~# ip a 1: lo:mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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: ens3: mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether fa:16:3e:f4:1e:fd brd ff:ff:ff:ff:ff:ff inet 51.77.149.182/32 scope global dynamic ens3 valid_lft 49349sec preferred_lft 49349sec inet6 fe80::f816:3eff:fef4:1efd/64 scope link valid_lft forever preferred_lft forever root@vps624512:~#
In this case,
IP = 51.77.149.182
Interface Name = ens3
Use “route -n” command to find out gateway.
root@vps624512:~# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 51.77.148.1 0.0.0.0 UG 100 0 0 ens3 51.77.148.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens3 root@vps624512:~#
GATEWAY = 51.77.148.1
Edit /etc/network/interfaces
vi /etc/network/interfaces
Add following
auto INTERFACE_NAME iface INTERFACE_NAME inet static address SEVER_MAIN_IP netmask 255.255.255.255 broadcast SEVER_MAIN_IP dns-nameservers 8.8.8.8 1.1.1.1 post-up route add GATEWAY_IP dev INTERFACE_NAME post-up route add default gw GATEWAY_IP post-down route del default gw GATEWAY_IP post-down route del GATEWAY_IP dev INTERFACE_NAME
In the above, replace INTERFACE_NAME, SEVER_MAIN_IP and GATEWAY_IP.
For this server, i added.
auto ens3 iface ens3 inet static address 51.77.149.182 netmask 255.255.255.255 broadcast 51.77.149.182 post-up route add 51.77.148.1 dev ens3 post-up route add default gw 51.77.148.1 post-down route del default gw 51.77.148.1 post-down route del 51.77.148.1 dev ens3
Now reboot the server.
Once server is back online, you can configure failover IPS.
Configure Failover IP
Use following script to generate your config, add in end of /etc/network/inferfaces file
php script to generate ip config
Once configured, you need to reboot the servr.
Verify IP is up with fping command.
Leave a Reply