it took me a while to get it all sweet so i thought it worthy of posting.
this tether is also working from a wifi-router > Galaxy S7 USB cellphone > the Linux router > a real router > my intranet.
but the wifi script can also be used if you don't want the cell-phone doing the wifi-usb routing.
>>> tether:
dhclient -r usb0
dhclient usb0
iptables -F
iptables -P INPUT ACCEPT
iptables -F INPUT
iptables -P OUTPUT ACCEPT
iptables -F OUTPUT
iptables -P FORWARD DROP
iptables -F FORWARD
iptables -t nat -F
iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o usb0 -j ACCEPT
iptables -A FORWARD -i usb0 -j ACCEPT
iptables -A FORWARD -i eth0 -o usb0 -j ACCEPT
service iptables status
route
>>> wifi:
# ! check: ee /etc/sysconfig/net*-scr*/ifcfg-wlan0
clear
echo "iw dev:"
iw dev
echo ""
echo "ip link show wlan0"
ip link show wlan0
echo ""
echo "ip link set wlan0 up"
ip link set wlan0 up
echo ""
#echo "scan ..."
#iwlist wlan0 scanning | more
#echo ""
# Once only, you get prompted for the password
# wpa_passphrase AndroidAPAE >> /etc/wpa_supplicant.conf
echo ""
echo "connecting now ..."
echo ""
wpa_supplicant -B wext -i wlan0 -c /etc/wpa_supplicant.conf
echo "iw wlan0 link ..."
sleep 2
iw wlan0 link
echo ""
dhclient -r wlan0
dhclient wlan0
iptables -F
iptables -P INPUT ACCEPT
iptables -F INPUT
iptables -P OUTPUT ACCEPT
iptables -F OUTPUT
iptables -P FORWARD DROP
iptables -F FORWARD
iptables -t nat -F
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
iptables -A FORWARD -i wlan0 -j ACCEPT
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
service iptables status
route
>>> additional scripts to swap between wifi access points (reboot required after):
/bin/wpa:
cat /etc/wpa_supplicant.conf
/bin/wpa-optus:
cp /etc/wpa_supplicant.conf-optus /etc/wpa_supplicant.conf
cat /etc/wpa_supplicant.conf
/bin/wpa-vodafone:
cp /etc/wpa_supplicant.conf-vodafone /etc/wpa_supplicant.conf
cat /etc/wpa_supplicant.conf
>>> ifcfg files:
DEVICE=eth0
HWADDR=00:13:D3:33:95:C6
TYPE=Ethernet
UUID=393aacde-bb81-49e7-967a-bb54a34ac85b
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
PEERDNS=yes
DEFROUT=yes
IPADDR=192.168.137.1
DEVICE=wlan0
TYPE=Wireless
BOOTPROTO=dhcp
BROADCAST=192.168.0.255
HWADDR=54:E6:FC:94:17:5E
NETMASK=255.255.255.0
ONBOOT=yes
ONHOTPLUG=yes
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
USERCTL=yes
IPV6INIT=no
CHANNEL=11
MODE=Managed
RATE=auto
my 3G/4G wifi and usb router scripts
Re: my 3G/4G wifi and usb router scripts
if you run into wlan0 hanging on a dhclient command then ensure that NetworkManager is stopped via chkconfig NetworkManager off