Skip to content

Instantly share code, notes, and snippets.

@nguyenl95
Last active Aug 22, 2018
Embed
What would you like to do?
multiple ppp usb on linux
#!/bin/bash
reset_iptables() {
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
}
reset_routes() {
ip route flush table main
echo "ip route show"
echo ">"
ip route show
ip route flush cache
echo "ip show cache"
echo ">"
ip route show cache
}
init_config() {
groupadd wheel
declare -a users=('user_vina', 'user_mobi') #...
declare -a interfaces=('eth0', 'wlan0') #...
for u in $users; do
useradd -G wheel -s /bin/bash $u
done
# FOR those rt_tabless
sudo bash -c 'cat <<EOF >/etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
200 user1
201 user2
EOF'
iptables -A OUTPUT -m owner --uid-owner 'user_vina' -j MARK --set-mark 0x1
iptables -A OUTPUT -m owner --uid-owner 'user_mobi' -j MARK --set-mark 0x2
if [[ `ip rule list | grep -c 0x1` == "0" ]]; then
ip rule add from all fwmark 0x1 lookup 'user_vina'
fi
ip route replace default via 192.168.1.1 table user_vina
ip route append default via 127.0.0.1 dev lo table user_vina
if [[ `ip rule list | grep -c 0x2` == "0" ]]; then
ip rule add from all fwmark 0x1 lookup 'user_mobi'
fi
ip route replace default via 192.168.1.1 table user_mobi
ip route append default via 127.0.0.1 dev lo table user_mobi
ip route flush cache
}
sudo_wheel_group() {
sudo bash -c 'cat <<EOF >>/etc/sudoers
%wheel ALL=(ALL) NOPASSWD: ALL
EOF'
}
reset_iptables
reset_routes
sudo_wheel_group
init_config
[Dialer Defaults]
Init = ATZ
Init = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Modem Type = USB
Modem Baud = 115200
Modem = /dev/ttyUSB0
Phone = *99#
Username = ''
Password = ''
Stupid Mode = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment