How do I add this rule to Iptables?
I currently have OpenVpn installed on my Debian 11 image and during it's installation it opened port 943. So OpenVPN talked to Iptables in the background to do this.
I am wanting to do the same (open port 443) for another application but I don't know the line of code to do this for iptables.
Below is a line that I copied when using iptables -L
AS0_WEBACCEPT tcp -- anywhere ###-###-###-###.ip.linodeusercontent.com state NEW tcp dpt:443
3 Replies
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
Note that this rule is for INBOUND traffic only. Outbound traffic is probably not blocked.
If it is, issue the same rule changing INPUT to OUTPUT.
ORDER IS IMPORTANT! You need to make sure these rules appear BEFORE the general rule blocking ALL traffic…especially on INPUT.
-- sw
Thanks stevewi,
Can I edit the iptables via a file? If so, where would that file be located? When I use port checker on my linode public IP it still says port 443 is closed.
Also, I need to route incoming connections on port 443 to 172.18.55.21:443. How can I add a route?
Can I edit the iptables via a file?
No. The actual iptables contents exists in kernel memory. You can only save/restore iptables contents to/from a file. If you’re adept at editing the output of iptables-save, I suppose you could do that. iptables-restore overwrites the kernel memory when it's loaded.
The output of iptables-save only marginally resembles iptables commands…
See the man pages for iptables-save/-restore.
When I use port checker on my linode public IP it still says port 443 is closed.
The order of your rules is wrong. Your rule opening port 443 is inferior (lower precedence) to your rule blocking port 443 (and prob lots of other ports as well). I don't usually recommend them but, in your case, I would use one of the "friendly front ends" to iptables (like ufw on Ubuntu).
Also, I need to route incoming connections on port 443 to 172.18.55.21:443. How can I add a route?
The easiest way is to configure a redirect in your web server…
— sw