<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by PHaroZ on Medium]]></title>
        <description><![CDATA[Stories by PHaroZ on Medium]]></description>
        <link>https://medium.com/@PHaroZ_?source=rss-21e83edf5997------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mnhq9L7xKNTmfulYeWapUw.jpeg</url>
            <title>Stories by PHaroZ on Medium</title>
            <link>https://medium.com/@PHaroZ_?source=rss-21e83edf5997------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 12:04:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@PHaroZ_/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Use OVH floating IP for outgoing traffic, including from containers]]></title>
            <link>https://medium.com/@PHaroZ_/use-ovh-floating-ip-for-outgoing-traffic-including-from-containers-cd03edaecc3?source=rss-21e83edf5997------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd03edaecc3</guid>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[ovh]]></category>
            <category><![CDATA[debian]]></category>
            <category><![CDATA[iptables]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[PHaroZ]]></dc:creator>
            <pubDate>Fri, 12 Nov 2021 13:19:15 GMT</pubDate>
            <atom:updated>2021-11-12T14:04:23.249Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*n4cz_qU4MaFMwUglehHlRg@2x.png" /></figure><p>This article aims to explain how to add a floating IP (a failover IP @ovh) to a linux server and use it for the outgoing traffic. We will use a Debian 10 server.</p><h3>Network interface</h3><p>Our server initially have a primary IP A.B.C.D associated to the interface enp3s0f0 :</p><pre># ip -4 a<br>1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000<br>    inet 127.0.0.1/8 scope host lo<br>       valid_lft forever preferred_lft forever<br>2: enp3s0f0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq state UP group default qlen 1000<br>    inet A.B.C.D/24 brd A.B.C.255 scope global dynamic enp3s0f0<br>       valid_lft 82105sec preferred_lft 82105sec</pre><p>We want to add the floating IP P.Q.R.S as an alias of enp3s0f0, to do so execute the command :</p><pre># ip addr add P.Q.R.S/32 dev enp3s0f0 label enp3s0f0:0</pre><p>Verify it :</p><pre>#ip -4 a show dev enp3s0f0<br>2: enp3s0f0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq state UP group default qlen 1000<br>    inet A.B.C.D/24 brd A.B.C.255 scope global dynamic enp3s0f0<br>       valid_lft 82105sec preferred_lft 82105sec<br>    inet P.Q.R.S/32 brd P.Q.R.S scope global enp3s0f0:0<br>       valid_lft forever preferred_lft forever</pre><h3>Routing</h3><p>At this step our server can be reached by its new IP, however the outgoing traffic still uses the main IP A.B.C.D.</p><p>A # curl ifconfig.me would return A.B.C.D, we also can check the routing table :</p><pre># ip r<br>default via A.B.C.254 dev enp97s0f0 <br>A.B.C.0/24 dev enp97s0f0 proto kernel scope link src A.B.C.D</pre><p>A.B.C.254 is the default routing gateway, it could be different (eg ends with .1) in an other network as it is provided by a DHCP server or is configured along with the primary static IP. Note it, as we will use it later.</p><p>So we have to replace the default route :</p><pre># ip route replace default via A.B.C.254 dev enp3s0f0 src P.Q.R.S</pre><p>Verify it</p><pre># ip r | head 1<br>default via A.B.C.254 dev enp3s0f0 src P.Q.R.S<br># curl ifconfig.me<br>P.Q.R.S</pre><p>Victory !</p><h3>Persist configuration</h3><p>To persist the changes done above (in case of a reboot, even if a linux server never needs to reboot 😄 ) we have to create a new file at /etc/network/interfaces.d/50-floatingIp (the file name doesn&#39;t matter) with the following content :</p><pre>auto enp3s0f0:0<br>iface enp3s0f0:0 inet static<br>        address P.Q.R.S/32<br>        up /bin/ip route replace default via A.B.C.254 dev enp3s0f0 src P.Q.R.S</pre><h3>Docker</h3><p>In the event our server has some docker — bridged — networks we have to check that our floating IP is also used for outgoing traffic :</p><pre># docker run --rm --network bridge curlimages/curl -sS ifconfig.me<br>A.B.C.D</pre><p>Humpf, this is not exactly what we want 😡 .<br>This is due to how docker routes outgoing traffic for bridged network : it uses MASQUERADing.</p><pre># iptables -t nat -nvL POSTROUTING<br>Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)<br> pkts bytes target     prot opt in     out     source               destination         <br>    3   174 MASQUERADE  all  --  *      !docker0  192.168.0.0/20       0.0.0.0/0</pre><p>In short, all outgoing traffic — which doesn’t target the docker bridge network itself — go through the appropriate network interface — of the host — and the emitting IP — of the container — is replaced by the first one — of the host — which is available for this interface. So here, our curl will be sent through the first public IP of enp3s0f0 which is A.B.C.D.</p><p>To change this behavior we have to use a NAT rule instead of a MASQUERADE one when the traffic should go out through enp3s0f0 :</p><pre># iptables -t nat -I POSTROUTING -o enp3s0f0 -s 192.168.0.0/20 -j SNAT --to P.Q.R.S</pre><p>Now look our changes :</p><pre># iptables -t nat -nvL POSTROUTING<br>Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)<br> pkts bytes target     prot opt in     out     source               destination         <br>    0     0 SNAT       all  --  *      enp3s0f0  192.168.0.0/20       0.0.0.0/0            to:P.Q.R.S<br>    3   174 MASQUERADE all  --  *      !docker0  192.168.0.0/20       0.0.0.0/0</pre><p>Note that we keep the MASQUERADE rule as it could be useful if our server has another network interface, for example in a private network.</p><p>Verify the result :</p><pre># docker run --rm --network bridge curlimages/curl -sS ifconfig.me &amp;&amp; echo<br>P.Q.R.S</pre><p>Fatality !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd03edaecc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>