{"id":470,"date":"2023-09-03T22:03:43","date_gmt":"2023-09-03T21:03:43","guid":{"rendered":"https:\/\/blog.inplico.uk\/?p=470"},"modified":"2025-02-21T21:59:51","modified_gmt":"2025-02-21T21:59:51","slug":"vodafone-broadband-multi-ip-setup","status":"publish","type":"post","link":"https:\/\/blog.inplico.uk\/?p=470","title":{"rendered":"Using the server as a router and firewall"},"content":{"rendered":"<p><strong>PPPOE<\/strong><\/p>\n<p>If you are using an ISP provided router then you probably will not need to set up pppoe, but if you are using a modem you will.\u00a0 From experience thus far it seems that FTP connection tend to work better with modems whereas FTTC have been better with routers.\u00a0 Vodafone multi IP in particular is much simpler to configure if you use the Vodafone router.<\/p>\n<p>If you are using a modem (or a router in modem mode) then you will need to connect it at both ends before you begin.\u00a0 Once you have it connected then install and run <strong>pppoeconf<\/strong> and follow the instructions on screen and all being well you will have a connection which you can manage with<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pon dsl-provider<\/pre>\n<p>to establish the connection or<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">poff dsl-provider<\/pre>\n<p>to disconnect.\u00a0 You can use ifconfig to review the connections.\u00a0 If you have one called ppp0 or similar with a public ip address assigned then you have a connection and should be able to access the internet from your server (curl https:\/\/www.debian.org should\u00a0 return the html for the debian website or you can just try an apt-get update).<\/p>\n<p>Now (DEBIAN STYLE OS):<\/p>\n<p>If you look at your <strong>\/etc\/network\/interfaces<\/strong> You will note a configuration for your ppp interface that looks something like<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">auto dsl-provider\r\n        iface dsl-provider inet ppp\r\n        pre-up \/bin\/ip link set eno2 up # line maintained by pppoeconf\r\n        provider dsl-provider\r\n<\/pre>\n<p>As you can see the line that says &#8220;line maintained by pppoeconf&#8221; identifies the physical interface that your modem is connected to (in my case eno2)<\/p>\n<p>(ARCH STYLE)<\/p>\n<p>Arch\/Manjaro et al do not have the luxury of an interfaces configuration file so we are just using stock systemd-networkd instead.\u00a0 It&#8217;s configuration file is in \/etc\/systemd\/network and doesn&#8217;t exist by default.\u00a0 Each file is given a name that starts with its precedence then the interface name and a &#8220;.network&#8221; suffix and they are processed in order of precedence so 10-xxx will be processed before 20-xxx:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">10-eno1.network\r\n20-eno2.network<\/pre>\n<p>This configuration is not using pppoe, just a standard connection and therefore we have a local interface and a WAN interface.\u00a0 In our example the local interface is 10 and the WAN is 20.<\/p>\n<p>The files contain the following respectively:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">[Match]\r\nName=eno1\r\n[Network]\r\nAddress=172.17.1.23\/16\r\n<\/pre>\n<p>for 10-eno1.network and<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">[Match]\r\nName=eno2\r\n[Address]\r\nAddress=xxx.xxx.xx.99\/24\r\n[Route]\r\nDestination=0.0.0.0\/0\r\nGateway=xxx.xxx.xx.97\r\nMetric=1\r\nGatewayOnLink=yes\r\n<\/pre>\n<p>:wFor 20-eno2.network; the WAN interface (where 99 is the address of the interface and 97 is the address of the gateway (this was set up against a Vodafone router which has a whole separate page dedicated to it on this blog).<\/p>\n<p>The systemd configuration above would be identical to the following stanza in the \/etc\/network\/interfaces file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">iface eno2 inet static\r\n        address xxx.xxx.xxx.99\r\n        netmask 255.255.255.0\r\n        broadcast xxx.xxx.xxx.xxx\r\n        post-up route add default gw xxx.xxx.xxx.xxx metric 1\r\n        post-down route del default gw xxx.xxx.xxx.xxx\r\n<\/pre>\n<p>systemd works out the broadcast for itself and automatically pulls the route when the interface is taken down.\u00a0 It has been rumoured\u00a0 that net-tools will be depreciated for some time now so I expect Debian will pull this method at some point but that rumour is around 10 years old now so don&#8217;t hold your breath.<\/p>\n<p>Incidentally, while testing I just used the ip command to bring the interfaces up and set them (this works for ether Debian or Arch based os so I will give a brief outline here:<\/p>\n<p>This method will liven up the interface but does not persist so you will\u00a0 have to use one of the methods above if you don&#8217;t want to set up the interface on every reboot.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ip set link up<\/pre>\n<p>brings the interface online.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ip addr add xxx.xxx.xxx.xxx\/xx dev eno1<\/pre>\n<p>sets an ip address and subnet mask.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ip route add default via xxx.xxx.xxx.xxx dev eno2<\/pre>\n<p>will establish a route so that you can access your server from the outside world through interface eno2 (Note: The ip address is that of your gateway, not your interface).<\/p>\n<p>If you have your dns set up correctly you should now have a link and be able to ssh to your server from the outside world.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>PORT FORWARDING<\/strong><\/p>\n<p>In order to pass traffic from one interface to another you need to enable port forwarding.\u00a0 To do so immediately issue<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">echo 1 &gt; \/proc\/sys\/net\/ipv4\/ip_forward<\/pre>\n<p>at the command prompt.\u00a0 To make this permanent you need to edit <strong>\/etc\/sysctl.conf <\/strong>and either add or uncomment the line<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">net.ipv4.ip_forward = 1<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>IPTABLES<\/strong><\/p>\n<p>WARNING:\u00a0 The interface will be different depending on your initial setup.\u00a0 If you are using pppoe with a single static ip then it is likely that every you will use <strong>ppp0<\/strong>; if you are connected to a router then it will likely be a physical interface such as <strong>eno1<\/strong>, <strong>eno2<\/strong>, <strong>eth1<\/strong>&#8230;. etc.\u00a0 In the examples here we are going to assume that your configuration is a singe static IP and your are using pppoe and a modem (or router in modem mode) therefore everything references the virtual interface <strong>ppp0<\/strong>.\u00a0 For other interfaces it is simply a matter of changing this (everything else is the same).<\/p>\n<p>To get things working properly we need to set up <strong>iptables<\/strong>.\u00a0 First thing to do is install <strong>iptables-persistent<\/strong> in the usual way and then back up any existing rules by issuing the command.<\/p>\n<p>Alternatively for Arch style distributions you can use systemd&#8217;s built in iptables service. the only real difference is the rules are stored in \/etc\/iptables\/iptables.rules.\u00a0 Setting them up is identical except for<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">DEBIAN:\r\niptables-save &gt; \/etc\/iptables\/rules.v4\r\nARCH:\r\niptables-save &gt; \/etc\/iptables\/iptables.rules<\/pre>\n<p>Now we need to set up a few new rules:<\/p>\n<ul>\n<li>Allow anything from the loopback interface; Here we assume that the loopback is <strong>lo<\/strong> but running <strong>ifconfig<\/strong> will confirm this.<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">iptables -A INPUT -i lo -j ACCEPT\r\n<\/pre>\n<ul>\n<li>Next, allow traffic from WAN to the router. Since it is dangerous to allow just anything from WAN, it should allow only packets that are part of a connection the router itself initiated. This prevents any random person on the internet from sending traffic to the router, but still ensures the router can still receive responses from the internet when it wants to.\u00a0 (CREDIT <a href=\"https:\/\/medium.com\/@voquangphu.a14\/making-a-self-made-debian-based-router-2d0e092ae38a\">Chris Vo<\/a>)<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">iptables -A INPUT -i ppp0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT\r\n<\/pre>\n<ul>\n<li>Allow packets from the LAN interface (in my case <strong>eno1<\/strong>) to be forwarded to the WAN (<strong>ppp0<\/strong>)<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">iptables -A FORWARD -i eno1 -o ppp0 -j ACCEPT\r\n<\/pre>\n<ul>\n<li>When we send packets from our <strong>LAN<\/strong> interface then well need to make it appear as though we were sending them from the <strong>WAN<\/strong> otherwise it may not know where to send any responses (it would also cause problems if every request appeared to come from a private subnet).\u00a0 We therefore want to create a rule that says that the <strong>LAN<\/strong> interface should <strong>MASQUERADE<\/strong> as the <strong>WAN<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE\r\n<\/pre>\n<ul>\n<li>Next we need tell our configuration which ports should be open to allow incoming traffic.\u00a0 In this example I am just going to open 53 for DNS on tcp and udp and 22 for ssh, but opening other ports is self explanatory<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">iptables -A INPUT -i ppp0 -p tcp -m tcp --dport 22 -j ACCEPT\r\niptables -A INPUT -i ppp0 -p tcp -m tcp --dport 53 -j ACCEPT\r\niptables -A INPUT -i ppp0 -p udp -m udp --dport 53 -j ACCEPT\r\n<\/pre>\n<ul>\n<li>Last but not least we need to set a rule that drops any requests to ports that have not been explicitly set as open<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">-A INPUT -i ppp0 -j DROP<\/pre>\n<p><span style=\"color: #ff0000;\"><strong>WARNING<\/strong>:<\/span>\u00a0 This must be the LAST rule as if you try and\u00a0 open any more ports then it will just ignore those rules.\u00a0 Inserting additional rules can be done by directly editing the <strong>rules.v4<\/strong> file (which we will explain how to do later).<\/p>\n<p>Next save your rules by issuing the command<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">iptables-save &gt; \/etc\/iptables\/rules.v4<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>OPENING ADDITIONAL PORTS<\/strong><\/p>\n<p>To open additional ports the easiest thing to do is edit the <strong>\/etc\/iptables\/rules.v4<\/strong> file directly and then restore it.\u00a0 The file will contain something like<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-highlight=\"8\">...\r\n-A INPUT -i lo -j ACCEPT\r\n-A INPUT -i eno1 -j ACCEPT\r\n-A INPUT -i ppp0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT\r\n-A INPUT -i ppp0 -p tcp -m tcp --dport 25 -j ACCEPT\r\n-A INPUT -i ppp0 -p tcp -m tcp --dport 53 -j ACCEPT\r\n-A INPUT -i ppp0 -p udp -m udp --dport 53 -j ACCEPT\r\n-A INPUT -i ppp0 -j DROP\r\n-A FORWARD -i eno1 -o eno2 -j ACCEPT\r\n...<\/pre>\n<p>Note the line <strong>-A INPUT -i ppp0 -j DROP<\/strong>. you will have to place any rules to open additional ports above this line.\u00a0 To close a port just delete the respective line.\u00a0 Here we are opening port <strong>80<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-highlight=\"8\">...\r\n-A INPUT -i lo -j ACCEPT\r\n-A INPUT -i eno1 -j ACCEPT\r\n-A INPUT -i ppp0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT\r\n-A INPUT -i ppp0 -p tcp -m tcp --dport 25 -j ACCEPT\r\n-A INPUT -i ppp0 -p tcp -m tcp --dport 53 -j ACCEPT\r\n-A INPUT -i ppp0 -p udp -m udp --dport 53 -j ACCEPT\r\n-A INPUT -i ppp0 -p tcp -m tcp --dport 80 -j ACCEPT\r\n-A INPUT -i ppp0 -j DROP\r\n...<\/pre>\n<p>Once you have finished editing the file you can apply it with the command<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">iptables-restore &lt; \/etc\/iptables\/rules.v4<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>CLIENT GATEWAY<\/strong><\/p>\n<p>Finally you will now need to set your client gateway to the address of your server (either manually on the clients themselves or on your dhcp server.\u00a0 You clients should now be able to connect to the internet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PPPOE If you are using an ISP provided router then you probably will not need to set up pppoe, but if you are using a modem you will.\u00a0 From experience thus far it seems that FTP connection tend to work better with modems whereas FTTC have been better with routers.\u00a0 Vodafone multi IP in particular [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-470","post","type-post","status-publish","format-standard","hentry","category-routers"],"_links":{"self":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=470"}],"version-history":[{"count":7,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/470\/revisions"}],"predecessor-version":[{"id":528,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=\/wp\/v2\/posts\/470\/revisions\/528"}],"wp:attachment":[{"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.inplico.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}