tun2socks

This commit is contained in:
2019-08-01 13:48:24 +01:00
parent 5102aa9680
commit c3082e10a8
3 changed files with 87 additions and 0 deletions

22
ssh_socks5.service Normal file
View File

@@ -0,0 +1,22 @@
# Automatically generated by systemd-sysv-generator
[Unit]
#SourcePath=/etc/init.d/rpcbind
Description=SSH SOCKS5 to yerevak.vostan.org
#DefaultDependencies=no
Before=shutdown.target
After=network-online.target local-fs.target
Wants=network-online.target
Conflicts=shutdown.target
[Service]
Type=simple
User=vahagn
Group=vahagn
Restart=always
RestartSec=2s
WorkingDirectory=/tmp
ExecStart=/usr/bin/ssh -N -D 0.0.0.0:1080 -i /home/vahagn/.ssh/id_rsa vahagn@yerevak.vostan.org
[Install]
WantedBy=multi-user.target

20
tun2socks.service Normal file
View File

@@ -0,0 +1,20 @@
# Automatically generated by systemd-sysv-generator
[Unit]
Description=tun0 to SOCKS5 tunel
Before=shutdown.target
After=network-online.target local-fs.target
Wants=network-online.target ssh_socks5.service
Conflicts=shutdown.target
[Service]
Type=simple
Restart=always
GuessMainPID=no
RemainAfterExit=yes
WorkingDirectory=/tmp
ExecStartPre=/usr/local/sbin/tun2socks_pre.sh
ExecStart=/sbin/ip netns exec soghancq /usr/local/sbin/tun2socks --tundev tun0 --netif-ipaddr 10.0.0.2 --netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:1080 --udpgw-remote-server-addr 127.0.0.1:7300
[Install]
WantedBy=multi-user.target

45
tun2socks_pre.sh Normal file
View File

@@ -0,0 +1,45 @@
#!/bin/sh
NETNS=soghancq
IP=/sbin/ip
NS="$IP netns exec $NETNS"
#
# Set ip forwarding.
# Do it from /ete/sysctl.conf
#sysctl -w net.ipv4.ip_forward=1
#
# Create network namesapce.
#
$IP netns add $NETNS
#
# Peer to peer to default namespace.
#
$IP link add veth0 type veth peer name veth1
$IP addr add 10.1.1.1/30 dev veth0
$IP link set veth0 up
$IP link set veth1 netns $NETNS
$NS $IP addr add 10.1.1.2/30 dev veth1
$NS $IP link set veth1 up
$NS $IP route add 127.0.0.0/24 via 10.1.1.1 metric 5
$NS $IP route add 192.168.0.0/24 via 10.1.1.1 metric 5
#$NS $IP route add 8.8.8.8 via 10.1.1.1 metric 5
#
# Configure tun0 which goes through socks5.
#
$NS $IP tuntap add dev tun0 mode tun user root
$IP link set tun0 netns $NETNS
$NS $IP addr add 10.0.0.1/24 dev tun0
$NS $IP link set dev tun0 up
$NS $IP route add default via 10.0.0.2 metric 6
#$NS /usr/local/sbin/tun2socks \
# --tundev tun0 \
# --netif-ipaddr 10.0.0.2 \
# --netif-netmask 255.255.255.0 \
# --socks-server-addr 127.0.0.1:1080 \
# --udpgw-remote-server-addr 127.0.0.1:7300 &