Only set vpn firewall if ethernet is connected

This commit is contained in:
Bob Mottram 2017-11-23 10:46:40 +00:00
parent 10e4cb3887
commit 9e7376f9ac
1 changed files with 17 additions and 15 deletions

View File

@ -355,6 +355,7 @@ function start {
brctl addbr $BRIDGE brctl addbr $BRIDGE
brctl addif $BRIDGE bat0 brctl addif $BRIDGE bat0
ifconfig bat0 0.0.0.0 ifconfig bat0 0.0.0.0
ethernet_connected='0'
if [ "$EIFACE" ] ; then if [ "$EIFACE" ] ; then
ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier) ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
if [[ "$ethernet_connected" != "0" ]]; then if [[ "$ethernet_connected" != "0" ]]; then
@ -452,6 +453,7 @@ function start {
iptables -A INPUT -p tcp --dport 8008 -j ACCEPT iptables -A INPUT -p tcp --dport 8008 -j ACCEPT
iptables -A INPUT -p udp --dport 8010 -j ACCEPT iptables -A INPUT -p udp --dport 8010 -j ACCEPT
iptables -A INPUT -p tcp --dport 8010 -j ACCEPT iptables -A INPUT -p tcp --dport 8010 -j ACCEPT
if [[ "$ethernet_connected" != "0" ]]; then
# vpn over the internet # vpn over the internet
iptables -A INPUT -p tcp --dport 653 -j ACCEPT iptables -A INPUT -p tcp --dport 653 -j ACCEPT
iptables -A INPUT -p udp --dport 653 -j ACCEPT iptables -A INPUT -p udp --dport 653 -j ACCEPT
@ -462,11 +464,11 @@ function start {
iptables -A FORWARD -i ${EIFACE} -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -i ${EIFACE} -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o ${EIFACE} -j MASQUERADE iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o ${EIFACE} -j MASQUERADE
iptables -A OUTPUT -o tun+ -j ACCEPT iptables -A OUTPUT -o tun+ -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/ip_forward
sed -i 's|# net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf sed -i 's|# net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
sed -i 's|#net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf sed -i 's|#net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
sed -i 's|net.ipv4.ip_forward.*|net.ipv4.ip_forward=1|g' /etc/sysctl.conf sed -i 's|net.ipv4.ip_forward.*|net.ipv4.ip_forward=1|g' /etc/sysctl.conf
fi
systemctl restart avahi-daemon systemctl restart avahi-daemon