SEO Explorer Blog:
Try us:

Configure OVH IP Alias (IP Failover), for dedicated server with CentOS 8 and Squid Proxy

Because we provide an SEO product, we need to have multiple proxies and IPs. Because we have the expertise, we prefer to use our own and not shared proxies.

But, with each Server Host, adding multiple IPs is different, and the instructions can be lacking.

We bricked the machine more than once, trying to configure multiple IPs, so we decided the way we used to configure 256 IPs with a dedicated server on OVH running CentOS 8 (it’s possible it will also work on ovhcloud)

After that, we configured Squid to relay to the IP based on the listening IP, and it took us a few days of research to get it working as well.

Disclaimer – We are not responsible for any damages by following this guide. Use it at your own risk.

Perquisites for OVH fail over IP

  • Buy additional IPs from OVH – They call it failover IP.
  • CentOS 8 (it could work on other Linux flavours).
  • Root access.

Setting up one new Failover IP on a dedicated server with Centos 8

Discovering the interface name

The first step is to discover the interface name, the files with all the interfaces is at /etc/sysconfig/network-scripts

The server we got; the interface is ifcfg-enp3s0f0

There are other common names like ifcfg-eth0 or ifcfg-ens3

You can check the name of the interfaces with the command: ifconfig

Creating a new interface file

We will copy the original interface to a new interface:

cp /etc/sysconfig/network-scripts/ifcfg-enp3s0f0 /etc/sysconfig/network-scripts/ifcfg-enp3s0f0:1

Modifying the network interface values

The original file looked like this:

BOOTPROTO=dhcp
DEVICE=enp3s0f0
HWADDR=xx:xx:xx:xx:xx
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no
IPV6INIT="no"

(We disabled IP6, you may not want to disable it)

The new file will look like this:

DEVICE="enp3s0f0:1"
BOOTPROTO=static
IPADDR="xxx.xxx.xxx.xxx"
NETMASK="255.255.255.255"
BROADCAST="xxx.xxx.xxx.xxx"
ONBOOT=YES

The IPADDR and BROADCAST have the same IP, which is our extra IP.

After we created that file, we need to reboot so the new network configuration will take effect.

Adding more than one IP to Centos 8

Creating network interface files manually

If there are only a few IPs to add, we can create more files, and the file names will be sequential, for example, enp3s0f0:2, enp3s0f0:3, enp3s0f0:4 (Make sure to modify the device name in the file as well)

And the IP will be sequential (if you bought multiple ranges, then use one IP per file)

Creating network interface files automatically

Creating a number of files is easy, but if you bought a large range of 32, 64, 128, 256 IPs, that’s just too much work.

We created a PHP script that will create the files (there are also range configuration, but it didn’t work for us, and sometimes you want a solution and not the perfect solution)

PHP Script to create network interface files

<?php

for ($f = 0;
     $f < 256;
     ++$f)
{
    $file = fopen('ifcfg-enp3s0f0:' . ($f+1),'w');
    fwrite($file,'DEVICE="enp3s0f0:' . ($f+1) . "\"\n");
    fwrite($file,'BOOTPROTO=static' . "\n");
    fwrite($file,'IPADDR="1.2.3.' . $f . "\"\n");
    fwrite($file,'NETMASK="255.255.255.255"' . "\n");
    fwrite($file,'BROADCAST="1.2.3.' . $f . "\"\n");
    fwrite($file,'ONBOOT=YES');

    fclose($file);
}

?>

Adjusting the PHP script

In the script, you need to change:

  • The first three numbers of the IP (we used 1.2.3 as a place holder).
  • If the IP range is not complete, in the line that writes ipaddr adjust $f to ($f+number) (the number is the last number of your first IP, so if the first IP is 1.2.3.4, it would be ($f+4).
  • The broadcast should have the same ($f+number) and the first three IP numbers.
  • If the device name is different, adjust the filename and the device to your server’s name.

After the files are ready, copy them to the /etc/sysconfig/network-scripts directory

Configuring Squid Proxy for multiple outgoing IPs

When using Squid out of the box, it will listen on all interfaces, but regardless of which interface the request came from, it will use the default IP to make the outgoing request.

We can configure Squid to route the request using the same IP the request came to by using this configuration:

acl ip1 myip 1.2.3.4
tcp_outgoing_address 1.2.3.4 ip1
acl ip2 myip 1.2.3.5
tcp_outgoing_address 1.2.3.5 ip2
  • Replace 1.2.3.4 and 1.2.3.5 with the server’s IPs
  • You can add more IPs, make sure to increase the IP alias to ip3, ip4, etc
  • These settings go into squid.conf

PHP script to configure Squid with multiple outgoing IPs

In the previous example, this is easy to add for several IPs, but if you bought many IPs, that becomes a time-waster. We wrote a script that writes those settings:

<?php

$file = fopen('squid.txt', 'w');

for ($i = 0;
     $i < 256;
     ++$i)
{
    fwrite($file, 'acl ip' . ($i+1) . ' myip 1.2.3.' . $i . "\n");
    fwrite($file, 'tcp_outgoing_address 1.2.3.' . $i . ' ip' . ($i+1) . "\n");
}

fclose($file);

?>

Adjusting the Squid PHP script

In the script, you need to change:

  • The first three numbers of the IP (we used 1.2.3 as a place holder).
  • If the IP range is not complete, in the line that writes ipaddr adjust $f to ($f+number) (the number is the last number of your first IP, so if the first IP is 1.2.3.4, it would be ($f+4).

After you run the script, take the content of squid.txt and add it to squid.conf (make sure to restart Squid so settings will take effect)

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Share via
Copy link
Powered by Social Snap