What's new

Restricting access to OpenVPN server via iptables

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

wrtuser

New Around Here
Hi! I’m allowing access to my OpenVPN server only for predefined ipset via rewriting existing iptables rules using openvpn-event user script.

What I’m currently doing: in openvpn-event I’m rewriting standard openvpn rule like:

Bash:
if iptables -C INPUT -p $proto -m $proto --dport $server_port -j ACCEPT; then
    iptables -D INPUT -p $proto -m $proto --dport $server_port -j ACCEPT
    iptables -I INPUT -p $proto -m set --match-set allow_ip src --dport $server_port -j ACCEPT
    logger -t "$scr_name" "Completed"
else
    # TBD...
    logger -t "$scr_name" "Failure: iptables rule not found to replace in the INPUT chain!"
fi


The same way I rewrite NAT rules. This works fine and is persistent between router reboots until I change something via GUI which causes iptables reload and my rule “iptables -I INPUT -p $proto -m set --match-set allow_ip src --dport $server_port -j ACCEPT” is rewritten back by original rule “iptables -C INPUT -p $proto -m $proto --dport $server_port -j ACCEPT” set by /etc/openvpnX/server/fw.sh.



What is the proper way to rewrite standard openvpn server rules set by fw.sh to make changes persistent between configuration changes which affects iptables?

And where /etc/openvpnX/server/fw.sh can be called during the changes within GUI which affects iptables?

386.4, RT-AC88U
 
The openvpn-event script is the correct location. Look at the specific event type however before determining what to do (through the $script_type variable value).


And where /etc/openvpnX/server/fw.sh can be called during the changes within GUI which affects iptables?
The script should be called whenever the firewall gets restarted.
 
Many thanks @RMerlin, I added rewriting of fw.sh default rules in my openvpn-event script, and now my custom iptables rules are persistent between firewall restarts too.
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top