Skip to content Skip to sidebar Skip to footer

Easy way to manage iptables on Ubuntu 16.04 VPS

Iptables on a virtual server is kind of Firewall which manages all directions from the port that has already been set. You can also block the traffic rate with the help of iptables outgoing who blacklist a website.

Just like a website that has bad elements for visitors, this server cannot open it, and a simple example is positive internet notifications.

Is it important to set up iptables on a VPS? It also depends on needs, and actually every VPS service has features too Network security group This is useful to make managing inbound and outbound ports very easy.

Also Read: Adding User ROOT SSH with Password Authentication on Ubuntu VPS

If you don’t have a function for it in the meantime, the last thing you can do is set it manually via iptables.

In this article I just want to give a simple tutorial on how to manage iptables on Ubuntu 16.04 (Xenial). Because in my opinion other Linux operating systems like Debian don’t require a complicated way of setting these iptables.

Even if users can be helped through the installation Webmin and put Firewall right from there, but from the terminal it’s much more accurate. In this article as an example I want to Make port forwarding from port 80 to 443 and that is guaranteed to be simple and hopefully understandable later. Just take a look below.

How to manage iptables on an Ubuntu 16.04 VPS

  1. Open a terminal and enter this command to install iptables specifically for Ubuntu 16.04.

    sudo apt-get install iptables-persistent -y

    Because if you don’t install it, iptables doesn’t seem to work when it’s implemented

  2. Next, port 80 is redirected to port 443. Here is the order.

    sudo iptables -A PREROUTING -t nat -i eth3 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.1:443sudo iptables -A FORWARD -p tcp -d 192.168.1.1 --dport 443 -j ACCEPTsudo iptables -A POSTROUTING -t nat -s 192.168.1.1 -o eth3 -j MASQUERADEsudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 443

    Remarks: Please replace 192.168.1.1 with the server IP of the user.

  3. Now that the above has been applied, just save it with this command.

    sudo invoke-rc.d netfilter-persistent savesudo iptables-save >/etc/iptables/rules.v4sudo ip6tables-save >/etc/iptables/rules.v6
  4. The final step is to restart the server or you can say restart

    sudo reboot

    After that, the user can see if port 80 is already open on the user’s server.

Remember that this method is just a simple example of port forwarding. To do other things, in the second step above, users can modify according to the iptables command they want.

And also remember to make sure every time a user enters a new iptables command save it with the command like above so that it is actually saved and used successfully.

Also read: tutorial on installing Webmin on an Ubuntu or Debian VPS

In the meantime, with the help of the website, you can see if the port is open like I said above Open the port checker. Because it normally does not appear on netstat even though it has been implemented correctly.

For more satisfactory results, I also recommend installing it Webmin to find out whether the iptables configuration has arrived in the system or not. If you have any questions please comment.

Hopefully useful and good luck