Things are getting even more interesting – I managed to achieve the desired result a couple of times, but for some reason it only takes about three minutes. I'll go over it step by step:
sudo ip tuntap add dev tun0 mode tun user username; //creating tun-interface
- sudo ip a add 10.0.0.1/24 dev tun0; //assigning 10.0.0.1 to it
- sudo ip link set dev tun0 up; //starting tun0
- sudo ifconfig; //checking is active
- badvpn-tun2socks --tundev tun0 --netif-ipaddr 10.0.0.2 --netif-netmask 255.255.255.0 --socks-server-addr 192.168.10.107:10808; //connecting to socks5 server
- ping 10.0.0.2 //checking data exchange
- sudo ip r a default via 10.0.0.2 metric 10; //route adding
- sudo ip r del default via 0.0.0.0 dev ens32 //removing default route through ens32 (optional)
- route -v //route table check
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 10 0 0 tun0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
192.168.10.0 0.0.0.0 255.255.255.0 U 100 0 0 ens32
192.168.10.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens32
- curl
https://myip.wtf/json //check it works through tunnel
{
"YourIPAddress": "
my_real_IP",
"YourLocation": "London, ENG, United Kingdom",
"YourHostname": "
my_real_IP",
"YourISP": "Kamatera Inc",
"YourTorExit": false,
"YourCity": "London",
"YourCountry": "United Kingdom",
"YourCountryCode": "GB"
}
Now all that remains is masquerade:
- sudo iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o tun0 -j MASQUERADE
checking:
sudo iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 241 packets, 15273 bytes)
pkts bytes target prot opt in out source destination
461 60995 MASQUERADE 0 -- * tun0 192.168.10.0/24 0.0.0.0/0
I point to the new gateway address 192.168.10.149 and DNS 8.8.8.8 – everything starts working, packets are flowing, and then after 3-5 minutes everything stops. On Ubuntu, nothing seems to be down. What could this be? I thought I configured everything correctly, didn't I?