joeaspinall
Posts: 1
Joined: Wed Dec 30, 2015 2:51 pm

Automatically Open a UDP Port Following Reboot

Wed Dec 30, 2015 3:03 pm

Hi - I've recently got myself a Pi and have followed a guide to have it run OpenVPN as a VPN server.

As part of this, I have to type in the following code after every reboot, to allow my client to connect to the Pi (on UDP port 1194):

Code: Select all

iptables -A INPUT -i tun+ -j ACCEPT
iptables -A OUTPUT -o tun+ -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
iptables -I FORWARD -i tun0 -o eth0 -s 10.8.0.0/24 -d 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 1194 -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
service openvpn restart
My question is: Is there a way to do things so that UDP port 1194 would be open automatically after each reboot (to save having to type in the above code each time)?

Many thanks.

User avatar
karrika
Posts: 1125
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: Automatically Open a UDP Port Following Reboot

Thu Dec 31, 2015 5:51 am

You can make the start of service permanent with a command

update-rc.d openvpn enable

Obviously you can disable it by

update-rc.d openvpn disable

The iproute settings can als be run at startup. Just make a script at /etc/init.d/iptables

And activate it for every boot with

update-rc.d iptables enable

Return to “Beginners”