File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
- wan=$( ip -f inet -o addr show eth0| cut -d\ -f 7 | cut -d/ -f 1)
3
- wlan=$( ip -f inet -o addr show wlan0| cut -d\ -f 7 | cut -d/ -f 1)
2
+
3
+ if dpkg-query -W needrestart > /dev/null 2>&1 ; then
4
+ sudo sed -i ' s/#$nrconf{restart} = ' " '" ' i' " '" ' ;/$nrconf{restart} = ' " '" ' a' " '" ' ;/g' /etc/needrestart/needrestart.conf
5
+ fi
6
+
7
+ # Get the interface name for the WAN connection using ip a command
8
+ INTERFACE_NAME=$( ip a | awk ' /state UP/ {print $2}' | tr -d ' :' )
9
+ if [[ $INTERFACE_NAME == * " w" * ]]
10
+ then
11
+ # WLAN connection detected
12
+ wan=$( ip -f inet -o addr show $INTERFACE_NAME | cut -d\ -f 7 | cut -d/ -f 1)
13
+ else
14
+ # Ethernet connection detected
15
+ wan=$( ip -f inet -o addr show $INTERFACE_NAME | cut -d\ -f 7 | cut -d/ -f 1)
16
+ fi
17
+
4
18
ppp1=$( /sbin/ip route | awk ' /default/ { print $3 }' )
5
19
ip=$( dig +short myip.opendns.com @resolver1.opendns.com)
6
20
@@ -34,10 +48,10 @@ if [ -z "$wan" ]
34
48
$( " sudo iptables -I INPUT -s $ip /8 -i ppp0 -j ACCEPT" )
35
49
sudo iptables --append FORWARD --in-interface wlan0 -j ACCEPT
36
50
else
37
- sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE && iptables-save
51
+ sudo iptables -t nat -A POSTROUTING -o $INTERFACE_NAME -j MASQUERADE && iptables-save
38
52
sudo iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE
39
53
$( " sudo iptables -I INPUT -s $ip /8 -i ppp0 -j ACCEPT" )
40
- sudo iptables --append FORWARD --in-interface eth0 -j ACCEPT
54
+ sudo iptables --append FORWARD --in-interface $INTERFACE_NAME -j ACCEPT
41
55
fi
42
56
43
57
clear
You can’t perform that action at this time.
0 commit comments