linusnilsson
September 13th, 2020, 09:53 AM
Hi.
I just did a fresh install of Ubuntu Server 20.04.1 LTS to act as a gateway for my LAN. I already had a working iptables-script which I want to use. I confirmed that the ufw.service was disabled, did a copy of its systemd-file and modified it to run my iptables-script. This works, except all the iptables-rules that depend on resolving a dns. So the rules that contain a hostname instead of an IP address causes errors which results in those rules not getting loaded at all.
I suspect this is caused by the firewall getting loaded before my internet interface and dns settings are completely up and running. If I immediately login and run the script manually I get no errors and all the rules, including those containing hostnames, gets loaded properly.
What would be the best solution to this?
As of now, I have some ideas:
Somehow delay the iptables-script from loading until all interfaces are up. The downside of this is that there will be a time when the internet interface is up and the firewall is not yet loaded, which I see as a security risk.
Somehow split the firewall into two parts. Load the first part, including rules that doesn't depend on an internet connection/dns. Then wait for the internet interface to come up and load all dns-dependent rules.
As most of the hostname-based rules are regulating access to services like ssh and openvpn, is there a way to make those rules load depending on the service? Like when openvpn starts, the rules regarding openvpn automatically gets loaded, and when it stops they get deleted? Is that somehow possible with iptables?
There might be other/better solutions out there that I'm not aware of so I'd appreciate every suggestion :)
I just did a fresh install of Ubuntu Server 20.04.1 LTS to act as a gateway for my LAN. I already had a working iptables-script which I want to use. I confirmed that the ufw.service was disabled, did a copy of its systemd-file and modified it to run my iptables-script. This works, except all the iptables-rules that depend on resolving a dns. So the rules that contain a hostname instead of an IP address causes errors which results in those rules not getting loaded at all.
I suspect this is caused by the firewall getting loaded before my internet interface and dns settings are completely up and running. If I immediately login and run the script manually I get no errors and all the rules, including those containing hostnames, gets loaded properly.
What would be the best solution to this?
As of now, I have some ideas:
Somehow delay the iptables-script from loading until all interfaces are up. The downside of this is that there will be a time when the internet interface is up and the firewall is not yet loaded, which I see as a security risk.
Somehow split the firewall into two parts. Load the first part, including rules that doesn't depend on an internet connection/dns. Then wait for the internet interface to come up and load all dns-dependent rules.
As most of the hostname-based rules are regulating access to services like ssh and openvpn, is there a way to make those rules load depending on the service? Like when openvpn starts, the rules regarding openvpn automatically gets loaded, and when it stops they get deleted? Is that somehow possible with iptables?
There might be other/better solutions out there that I'm not aware of so I'd appreciate every suggestion :)