Solution to Tethering + OpenVPN issues on KitKat/4.4 - Nexus 5 Q&A, Help & Troubleshooting

I was previously using a stock rooted Nexus 4 (with 4.3) with "OpenVPN Connect" (net.openvpn.openvpn) and android built-in wifi tethering to tunnel tethered clients through the OpenVPN connection. This required some iptables modifications but worked fine.
With a stock rooted Nexus 5 (with 4.4.0) and OpenVPN Connect 1.1.12, this stopped working and that was really annoying.
Part of the issue was the one described here
But it was more complicated. It seems that there are routing table issues that I had to research a bunch.
Here are the iptables commands that I already had to run even on the Nexus 4 (with 4.3), which I got from here
Code:
iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -I FORWARD -j ACCEPT
iptables -t nat -I POSTROUTING -j MASQUERADE
These (above) are somewhat liberal firewall rules that you may what to refine for more security.
But below are additional routing entries that I needed to add specifically for the Nexus 5 (with 4.4.0). They force tethered clients to route through the VPN, unless their traffic is a broadcast or designated for the wifi LAN. Those exceptions are required for DHCP to work on the tethered client. They assume the tethered LAN is 192.168.43.XYZ and the OpenVPN interface is tun0.
Code:
ip rule add from 192.168.43.0/24 lookup 61
ip route add default dev tun0 scope link table 61
ip route add 192.168.43.0/24 dev wlan0 scope link table 61
ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61
This seems to all work best if I start OpenVPN after activating tethering, not before.
I'm not entirely clear whether this is a result of some change/bug in KitKat, or an incompatibility in "OpenVPN Connect", or both. I wonder if it would work ok with other OpenVPN clients like "OpenVPN for Android" (de.blinkt.openvpn)
Other Notes:
* Server is OpenVPN 2.3.2
* Server has this line set in its config:
Code:
push "redirect-gateway autolocal def1"

Running android 4.4.2 google stock image with SuperSU on LG Nexus 4. These routing commands worked great and allowed me to tunnel all WiFi tethered traffic through my VPN. Thanks for figuring this out it was bugging me!

Im stock 4.4.2 no root or anything just pure stock i download install openvpn from google play and imported my config files click connect then open PDAnet connect and the Ip is changed.

OK, so I'm having a bit of trouble understanding and implementing the fix for my nexus 5. I've already got WiFi tethering working through the sqlite db fix but now I can't get my connection to work when my VPN (PIA official app) is broadcasting. These commands you're sending, are they done on the phone terminal or computer and is that EXACTLY how theyre being entered. For rules in red where would I find the IP I would use. Thanks guys Id really appreciate any help given.

Worked!
scootley said:
This seems to all work best if I start OpenVPN after activating tethering, not before.
Click to expand...
Click to collapse
Thanks scootley! These worked me on 4.3. I activated my hotspot before OpenVPN, but I used
Code:
iptables --flush
first before entering your commands. Seems to help. My OpenVPN server config also has the following in addition to push redirect:
Code:
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
push "redirect-gateway autolocal def1"
Jrock2t5 said:
OK, so I'm having a bit of trouble understanding and implementing the fix for my nexus 5. I've already got WiFi tethering working through the sqlite db fix but now I can't get my connection to work when my VPN (PIA official app) is broadcasting. These commands you're sending, are they done on the phone terminal or computer and is that EXACTLY how theyre being entered. For rules in red where would I find the IP I would use. Thanks guys Id really appreciate any help given.
Click to expand...
Click to collapse
These commands are entered on the phone. You can download Terminal Emulator or something similar through the app store.
First make sure you're connect to your hotspot from your computer. Next, let's find your local IP address. Here are the instructions for Windows:
Click on the Start menu and type cmd. When you see the cmd applications in Start menu panel, click it or just press enter.
A command line window will open. Type ipconfig and press enter.
You'll see a bunch of information, but the line you want to look for is "IPv4 Address." The number across from that text is your local IP address.
Here's how to do the same thing on a Mac:
Open System Preferences (via the Apple menu at the top lefthand corner of your screen).
When System Preferences opens, click on the icon labeled Network.
You should see a few options on the left with labels like Wi-Fi, Ethernet, Bluetooth, etc. The ones with green dots have IP addresses assigned to them. Click the one on top (if it isn't already selected) and look to the right. There should be a sentence that reads something like "Wi-Fi is connected to Chocolate and has the IP address 192.168.1.102." The number at the end of that sentence is your local IP address.

Thanks for this thread, I've nearly got tethering working through Private Internet Access/Open VPN.
When running the commands
Code:
ip rule add from 192.168.43.0/24 lookup 61
ip route add default dev tun0 scope link table 61
ip route add 192.168.43.0/24 dev wlan0 scope link table 61
ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61
i get an error "RTNETLINK answers: File exists"
I tethered up while connected to the VPN and could ping out to external IP addresses but no DNS resolution. So in my windows settings I manually specified DNS settings and can now browse the web through the VPN on my Galaxy s4!
But how do I fix the DNS issue? I want the clients that connect to pick up the DNS settings that actually work, without having to manually specify.
Thanks for any help

Vpn problem
Hi I havent tried the above options..yet
I have a sgs3 sgh-t999 . a comercial vpn account with the xxx.ovpn cert files.
after getting the details entered into open vpn and importing the cert file all is good untill I go to connect [see attachment]
phone is v4.3, baseband mjc, kernel v 3.0.31, rom S3rx v3.0 1-27-14
any suggestions on how to proceed?

RXP said:
Thanks for this thread, I've nearly got tethering working through Private Internet Access/Open VPN.
When running the commands
Code:
ip rule add from 192.168.43.0/24 lookup 61
ip route add default dev tun0 scope link table 61
ip route add 192.168.43.0/24 dev wlan0 scope link table 61
ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61
i get an error "RTNETLINK answers: File exists"
I tethered up while connected to the VPN and could ping out to external IP addresses but no DNS resolution. So in my windows settings I manually specified DNS settings and can now browse the web through the VPN on my Galaxy s4!
But how do I fix the DNS issue? I want the clients that connect to pick up the DNS settings that actually work, without having to manually specify.
Thanks for any help
Click to expand...
Click to collapse
1) RTNETLINK answers: File exists
This just means you already ran the command before during this reboot session and it's saved into the route table. If you restart your phone, and run the commands again, it will go through first time, but repeated commands will yield same error. Should be normal. Table clears on reboot.
2) Please see the thread at http://forum.xda-developers.com/galaxy-s2/help/solved-wifi-hotspot-issue-samsung-t1689242
It seems like in order for OpenVPN DNS push to work, you have to change your APN settings on your phone to have it automatically register and push out to your other devices. I had the same problem and came across this during a search.

Massive thanks to the OP for posting this here and to everyone helping out in this thread.
The above rules route wifi tethered traffic via the vpn but I was wondering if there are similar rules to route usb tether too?
Cheers

It seems to work once, but when Data connection is lost or openvpn reconnects, wifi tathering stops working, need to do everything again (switch all off, connect to 3G, vpn, create wifi hotspot and apply fix script). And somehow DNS doesn't work. Tryed on Galaxy S5, LG L70, both on 4.4.2
But in general, this workaround is working, just needs a little bit of tweaking

This is fantastic.
For those of you using VPN on your phone as well, does it seem to stay connected? My VPN (OpenVPN) was flawless on 4.3 ... I mean smooth as ice with no disconnects.
When I upgraded to Kitkat, I wanted to immediately hide in a hole from embarrassment. Only after trying to connect and stay connected did I start to read around to check what the heck was going on. Biggest mistake ever. But then again, who would have thought right? I mean come on...who would have thought it would make using VPN a nightmare after an update that's suppose to be improved? Whatever...
Anyhow, lesson learned. Now I'm waiting desperately for someone to figure out how to downgrade from 4.4 back to 4.3 and/or to find a patch/fix for this issue so we don't have to run a script on every boot or reset.
At the end of the day, at least there is a solution thanks to folks like you. Kudos to the OP and everyone else who has contributed to the work around...for the time being lets hope...
:good:

For anyone interested, I played with the commands to have it work over a USB tether instead of Wifi. Why? Because my battery life stinks and this way my phone is charging also. What the heck. works great.
The only change was in the two spots where it has "wlan0" change them to "usb0". Another change was that the subnet of the USB connection is 192.168.42.0/24 (versus 192.168.43.0/24 on wifi). I get it working in this order:
1) reboot phone (to make sure to other lingering route tables are wiped out
2) turn off wifi
3) establish VPN connection
4) start USB tethering (and have your phone usb connected to your computer
5) After eveything is hooked up, open a terminal window, make sure you have superuser access (su) and execute the commands below. I just have them saved in a text file on my phone's sd card, copy them and just paste them all at once into the terminal window. Haven't figured out how to get this to run automatically using init.d (yet - assuming you can because upon phone reboot, I have to assuming that it will spit out errors because the tun0 and usb0 devices will not exist!)
iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -I FORWARD -j ACCEPT
iptables -t nat -I POSTROUTING -j MASQUERADE
ip rule add from 192.168.42.0/24 lookup 61
ip route add default dev tun0 scope link table 61
ip route add 192.168.42.0/24 dev usb0 scope link table 61
ip route add broadcast 255.255.255.255 dev usb0 scope link table 61

Vpn api delete route joy downgraded
@grogargh
Have you tried Tasker, run shell
To run after booting [or from widget or otherwise]
http://forum.xda-developers.com/showthread.php?t=1110775

Related

Real Tethering via Bluetooth!

Disconnect from #android on freenode figured out how to get bluetooth tethering to work. It requires root access of course.
http://www.gotontheinter.net/node/515
Enjoy!
BTW, I just tried and this *does* work for windows. Once you run the pand command on the phone, then go back to your computer and right click on the bluetooth icon in the system tray and select "Join a Personal Area Network". Then click "Refresh" in the dialog that pops up, then select the G1 and click connect.
Now you should have a "Bluetooth Network Connection", and you have to set it up with a static ip like Disconnect's post describes.
Wow the Real Hacking is started !
Rock and Roll!
That's pretty nice
Will wait for the DHCP version though, and I am still hoping for a USB way to do it, since Server 2008 and Bluetooth is a nightmare >.<
I keep getting read-only errors when copying into /system/xbin. I've remounted /system as read-write too. (RC30 v1.2)
And if I try to execute pand from /sdcard, I get Permission Denied errors.
Any thoughts, anyone?
The /system/xbin folder is a mounted cramfs image. So is /system/modules. Cramfs is a readonly file system.
I had to use cramfs to compress those two folders because it wouldn't all fit in /system otherwise.
If you really want to add/change something, unmount the folder, and you'll see an xbin.cramfs file in the folder instead. Download that to your computer and use the tools provided by the cramfs project to extract and repack it. Keep in mind the space limitations in /system. There isn't much space left at all
When I run this, the network interface bnep0 isn't created. Here's what happened:
I modified the tether script over in the iptables thread to load the bnep.ko module and run pand, etc.
When I ran my new script, I got an error because I forgot to set the execute permissions on pand. So, I changed the permissions.
Before I went to run the script again, I wanted to get back to my original state, so I tried to 'rmmod bnep'. That failed. I ran 'ps', and saw this process: kbnepd bnep0. I tried to kill it, which didn't work. I turned off BT from the UI, and the process ended. Then I did an rmmod bnep, and it worked.
I re-enabled BT from the UI, and went to run my script again. This time I got a new error and discovered it came from ifconfig. Sure enough, if i run 'busybox ifconfig -a' there is no interface named bnep0. When I did a 'ps' there was no longer this process called kbnepd bnep0.
I have rebooted the phone several times, recopied the module, and even upgraded to JF's v1.2 ROM (from v1.1). Still, whenever I do an 'insmod pathtomodule/bnep.ko', no network interface is created (there are no errors that output to the screen either and 'rmmod bnep' works as well with no errors).
Any ideas?
P.S. In the "Wireless controls" UI, when you tap the Bluetooth checkbox, does the text below remain "Select to turn on Bluetooth" when BT is enabled?
jbruer said:
When I run this, the network interface bnep0 isn't created.
Click to expand...
Click to collapse
Doh... the network interface isn't created until pand gets an incoming connection. pand has an option to run a script when the interface comes up, so I'll try to use that to run the rest of my setup script.
FYI..
I played around with this setup today and the adhoc-wifi tethering is much easier to setup and a lot faster.
Tethering via bluetooth I was only seeing about 70Kb/s, while Tethering via wifi I'm seeing 300+Kb/s.
Not sure if this is a bluetooth issue or what, but getting the bluetooth connection up and running is a pain in the ass compared to adhoc wifi.
Like others have stated, you have to start the pand service(also make sure in bluetooth settings the g1 is discoverable, only lasts 120 seconds) once the connection is established you can complete the other setups...
Hey, thanks for the tip about the calling the script. The connection speed sucks, but at least the setup is easier.. You still need to turn on bluetooth, and make it discoverable so windows can see the NAP and connect to it..
Here's my setup: I use dsnmasq for DHCP...
(blue.sh)
#!/system/bin/sh
insmod /data/local/bin/bnep.ko
/data/local/bin/pand --listen --role NAP --devup /data/local/bin/blue2.sh
(blue2.sh)
#!/system/bin/sh
ifconfig bnep0 192.168.2.1 netmask 255.255.255.0
ifconfig bnep0 up
/data/local/bin/iptables -F
/data/local/bin/iptables -I INPUT -s 192.168.2.254 -j DROP
/data/local/bin/iptables -I FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
/data/local/bin/iptables -I FORWARD -s 192.168.2.0/24 -j ACCEPT
/data/local/bin/iptables -I FORWARD -s 192.168.2.254 -j DROP
/data/local/bin/iptables -P FORWARD DROP
/data/local/bin/iptables -t nat -I POSTROUTING -s 192.168.2.0/24 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
/data/local/bin/dnsmasq -x /data/local/bin/dnsmasq.pid
parrothd said:
FYI..
Tethering via bluetooth I was only seeing about 70Kb/s, while Tethering via wifi I'm seeing 300+Kb/s.
Click to expand...
Click to collapse
Can anyone else reproduce this? (FYI it will share a wifi link but unfortunately, I'm in EDGE and my wifi is WPA2 .. so my wifi connectivity only lasts 5-10 seconds at a time, and edge is.. well.. edge..)
Disconn3ct said:
Can anyone else reproduce this? (FYI it will share a wifi link but unfortunately, I'm in EDGE and my wifi is WPA2 .. so my wifi connectivity only lasts 5-10 seconds at a time, and edge is.. well.. edge..)
Click to expand...
Click to collapse
I can confirm this. I'm in an EDGE area this weekend, so I tested by sharing a Wifi connection. Speedtest on the phone gave 4 Mbps down. Sharing over BT gave 89 kbps down. Also, when I ping the phone while connected to the PAN, I get latency around 30-50ms. Latency to google.com using the shared Wifi was around 250ms.
This may not be related, but if you look in the git for the Dream platform, init.trout.rc has this section: (http://android.git.kernel.org/?p=platform/vendor/htc/dream.git;a=blob;f=init.trout.rc;h=de41a72986890868b07d34c347245396be9f8f90;hb=HEAD)
Code:
64 service hciattach /system/bin/hciattach \
65 -n -s 115200 /dev/ttyMSM0 texas 115200 flow
66 user bluetooth
67 group bluetooth net_bt_admin
68 disabled
I know that hciattach is the BT service, and it appears that its creating a 115k baud serial port. The module we load emulates an ethernet adapter (bnep0), but I'm not sure if this serial device has any relation. Anybody around here know what the deal with this is?
Hmm. that's a good point. I'll play around with it a bit today and see if it's related
Just a quick update on this, google is working on a faster bluetooth driver, which will (automagically) make this faster too.
parrothd said:
Hey, thanks for the tip about the calling the script. The connection speed sucks, but at least the setup is easier.. You still need to turn on bluetooth, and make it discoverable so windows can see the NAP and connect to it..
Here's my setup: I use dsnmasq for DHCP...
...
/data/local/bin/dnsmasq -x /data/local/bin/dnsmasq.pid
Click to expand...
Click to collapse
WOW! Nice job. Could you please put your compiled dnsmasq somethere?
Strange thing. I setuped everything. Seeing iface on my phone via busybox ifconfig. Phone could ping himself via it's bluetooth IP.
Also PC could itself. Ifaces up and active on both sides.
But on PC I am having 0 recieved packets thru virtual bluetooth nic. While on phone i am having both RX and TX. And funny thing what RX on phone is exactly equal to TX on PC. So actually connection working but only one way...
WTF is what? Haven't even idea which way to look into this problem. Anyone have any idea about that?
hmepas said:
WOW! Nice job. Could you please put your compiled dnsmasq somethere?
Click to expand...
Click to collapse
i didn't compile it, but it's available in the iptables thread, if you can't find it I'll post it, having said that, you can also use udhcpd from busybox as well...
parrothd said:
i didn't compile it, but it's available in the iptables thread, if you can't find it I'll post it, having said that, you can also use udhcpd from busybox as well...
Click to expand...
Click to collapse
Oh thanks. I found it easily.
Btw could explain those two lines in your script:
Code:
/data/local/bin/iptables -I INPUT -s 192.168.2.254 -j DROP
/data/local/bin/iptables -I FORWARD -s 192.168.2.254 -j DROP
any secret here? for me those lines is complete useless. Or it's just your local issue which you didn't clean up before publishing script?
They're not needed, but you may want them.
dnsmasq and probably busybox udhcp will only start if you have at least 1 ip available for DHCP assignment(as far as I can tell).
This allows anyone to connect to your G1 mobile when in ad-hoc wifi mode and get access to the internet. Probably something you don't want to allow, with the limited speed and caps.
I use dnsmasq to staticly assign my laptop 192.168.2.30(cux I'm lazy and don't want to manually assign my IP), while assigning everyone else that connects to my G1 IP 192.168.2.254 which I then drop all access via iptables, so they have no access.
If you can figure out how to get dnsmasq or busybox udhcp to provide only static IP assignments then this is not needed...
My dnsmasq.conf changes..
# Uncomment this to enable the integrated DHCP server, you need
# to supply the range of addresses available for lease and optionally
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
# service.
dhcp-range=192.168.2.254,192.168.2.254,30m
# Always allocate the host with ethernet address 11:22:33:44:55:66
# The IP address 192.168.0.60
dhcp-host=00:13:ce:b7:a8:0e,192.168.2.30
I found that if you set the lease time to 0, dnsmasq will not assign an IP address unless it's statically assigned. You still should setup some filtering to keep people of your network, but most users won't bother trying to figuring that out.
# Uncomment this to enable the integrated DHCP server, you need
# to supply the range of addresses available for lease and optionally
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
# service.
dhcp-range=192.168.2.254,192.168.2.254,0

Motorola Milestone Ad-hoc wifi for the needed

After trying several methods (tiwlan.ini, wpa_supplicant.conf, wpa_supplicant patch) to get my Motorola Milestone to connect to my Laptop's Adhoc wifi network with no success, i finally come up with a solution. Now I am sharing it here hoping it will help those with the same problem.
The idea is to use Barnacle (on Market) to first setup a connection with the laptop, then re-config it to make the sharing work in the reverse direction.
Steps are as followed:
1. Start Barnacle (you may check "Local Mode" in Settings to go ahead without a data connection in phone), then connect your laptop to the wireless network it creates (named milestones or so). After this step, your phone's IP will be something like :192.168.5.1, and your Laptop's IP will be something like: 192.168.5.100
2. Start sharing your data connection from Laptop, in doing that, your Laptop's IP will be forcibly set to 192.168.0.1 (yours may be different, just note that this IP will be used as default gateway we use in the next step)
3. Now the configuration part:
//Start adb shell by entering at Cmd prompt
adb shell
$
su
#
//mannualy set IP for your phone, can be anything in form of 192.168.0.xxx
# ifconfig tiwlan0 192.168.0.2 netmask 255.255.255.0
//manually set the default gateway of the phone to the Laptop's IP at this time
# route add default gw 192.168.0.1 dev tiwlan0
After these steps, the phone can access the internet via the Laptop's connection. We will complete the remaining by manually specifying a DNS for the phone
# setprop net.dns1 #.#.#.# (here you should replace the #.#.#.# to a known IP address of your ISP's DNS, in worst case you may use Google's DNS)
//Now test with ping to see if we receive any response:
# ping -c 4 192.168.0.1 => the Laptop should answer
# ping -c 4 191.168.0.2 => phone are pinging itself, the phone should answer
# ping -c 4 209.85.175.106 => some server in the Internet should answer
# ping -c 4 www dot google dot com => Google should answer
If the tests above are all OK, you are done, enjoy the internet from your phone !
have tried :
+ Mail OK
+ Browser OK
+ Internet radio OK
+ Market nearly OK (in here the app browsing is OK, but download seem stuck)
Please confirm your result,
Codelavie
not working. i follow your guide exactly, but it didn't work. how can you do that? where am i wrong?
Didn't work for me either. After quite a hard experience I've managed to compile a wpa_supplicant with adhoc support for Milestone 2.1-update1 after applying szym's patch, and so far it works fine. The only thing you need to do is substituting the original system/bin/wpa_supplicant for the patched one, and restart wifi. I cant post the link yet because I'm new in the forums, but I'll post it as soon as i can.

Tethering with OpenVPN: How to avoid ATT's prying eyes and possibly tether undetected

The purpose of this post is to explain how to tether with openvpn, which will hopefully avoid ATT's all seeing eyes, as well as prevent any detection during tethering.
All ATT will ever see is encrypted traffic between a connection that is initiated from my phone and ends at my vpn server. So the only way they would be able to determine if you are tethering, is if they are spying on you ala CIQ directly on your device, or your device phones home and tattles on you. That would open up a different can of worms and a **** storm would ensue.
This method requires a number of things.
* Openvpn server (preferably running on a static address, but will work with dynamic DNS services) with a reliable connection. I use a VPS server for $25 a month, but it is fast and reliable.
* Openvpn on your phone (any will work as long as it has the tun driver or tun built into the kernel(
* Some sort of gateway (your openvpn server can be running on it as well, or a seperate host), I use Freebsd/Openbsd. For linux, your on your own to figure out NAT and gateway functions.
Really, that is about it.
My Openvpn server config, you can set it up any way you like, but certain statements are required, specifically those in the hashed out box if you want your subnets to talk to each other, and route the traffic
Code:
port ****
proto tcp
dev tun
ca /usr/local/etc/openvpn/keys/ca.crt
cert /usr/local/etc/openvpn/keys/vps.server.crt
key /usr/local/etc/openvpn/keys/vps.server.key
dh /usr/local/etc/openvpn/keys/dh2048.pem
server 192.168.150.0 255.255.255.0
ifconfig-pool-persist ipp.txt
mode server
client-to-client
client-config-dir ccd
###############################################
# my phone and home subnets, can be any RFC1918 address space
# Advertise and note your home subnets in this section, unless you
# do not want the various subnets to talk to each other, then you
# can also remove the client-to-client statements
###############################################
push "route 192.168.15.0 255.255.255.0"
push "route 192.168.43.0 255.255.255.0"
route 192.168.15.0 255.255.255.0
route 192.168.43.0 255.255.255.0
###############################################
keepalive 10 120
comp-lzo
persist-key
persist-tun
status /var/log/openvpn/openvpn-status.log
log /var/log/openvpn/openvpn.log
log-append /var/log/openvpn/openvpn.log
verb 4
My client config on my phone (change the remote statement to match your openvpn server host and port)
Code:
client
proto tcp
dev tun
remote vpn.example.com 1234
nobind
persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
comp-lzo
/usr/local/etc/openvpn/ccd is where I have my client specific configs (match the location to that identified in the server.conf file for your vpn server). I also use certificates unique to each host that connects to my vpn, the names of the files in the "ccd" directory must match the name you gave the device when you created your certificates. I use easy-ssl to manage my certs.
for my phone, which I named "galaxy_s" I have the following (note the DNS option is optional, I was having problems with it so I just hardcoded 8.8.8.8, googles dns server into my network settings on my laptop)
/usr/local/etc/openvpn/ccd/galaxy_s
The iroute statement just tells the openvpn server what subnets you have behind your device, in this case the phone. I am guessing all of the android phones use 192.168.43.x as the NAT'd subnet, otherwise change it to whatever your phone is assigning.
Code:
push "redirect-gateway"
push "dhcp-option DNS 192.168.15.1"
iroute 192.168.43.0 255.255.255.0
The rest of the configurations are related to your primary gateway, which in my case also runs the openvpn server. I am using freebsd and pf, the configs needed for that are essentially natting statements, and firewall rules.
for pf, the following rules are what I use
I also trust all the traffic on my tun0 device, so I told pf to ignore it and pass all traffic
Code:
nat on $int from 192.168.150.0/24 to any -> $int/32
nat on $int from 192.168.43.0/24 to any -> $int/32
set skip on tun0
Hopefully this is useful to other folks, if not, let it be buried
THanks for an EXCELLENT guide!
Quick question. When I use this server conf file, my ssh on my local network hangs up and goes down.
In other words:
I am running openvpn on a home linux server. It is connected through a home router to the internet and has a network set up at 192.168.1.0.
Router is 192.168.1.1,
vpn server is on 192.168.1.51.
If I start openvpn, I cannot ssh from a local network (192.168.1.81) laptop. If I turn off openvpn I can. I changed your 192.168.15.0 addresses in server conf file to 192.168.1.0. I have a feeling it has to do with that.
Well, yes, you will need to modify the configs to suit your own address scheme. As for why you cannot ssh, I am not sure, is that .81 device on the same network as the openvpn server, or are you coming from a different network.
My setup has the gateway the same as the openvpn server simply due to the fact that I am using a Virtual Private Server (VPS) and I only have that as the 1 external static system.
I would check the route statements, I'm not sure, but you might have a routing loop that would be causing the problem, can you traceroute or ping, or use any other protocol/application to see if you can connect). If you set the default gateway of the openvpn server as the .1 address, and then you are trying to connect to another internal address, the .81, when you ssh from whatever device is connected to the openvpn server, it may attempt to connect to the gateway at .1 and then return back into your network to .81.
I could be wrong, it is hard to tell when you are not sitting at the actual systems.
Got it to work! Here's some tips for others
Thanks again for your help jvanbrecht. Last night I was able to sit down, get a better understanding of how it worked via openvpn's HOWTO, and get it running.
I did need to make a few mods for it to work in my configuration (as is expected since very few network configs are the same).
My configuration:
Single home network, say on 192.168.15.0.
Single router, at 192.168.15.1.
Home server hosting VPN on 192.168.15.51. It is running Ubuntu Maverick.
Skyrocket on subnet 192.168.43.0
My modifications:
Since I don't need direct access between VPN clients and my home subnetwork, in the server config I commented out:
Code:
#push "route 192.168.1.0 255.255.255.0"
#route 192.168.1.0 255.255.255.0
It was giving me some problems SSHing into my home server from a local network machine so this was the quick fix.
Initially it wasn't routing ALL traffic, just that directed from VPN client to the VPN server. So I added this to the server conf:
Code:
push "redirect-gateway def1"
push "dhcp-option DNS 192.168.150.1"
In my home (tomato) router, I just port forwarded any TCP traffic on 1194 to the home server (192.168.15.51)
I think openvpn does this already. But just in case, I added an iptable nat entry to forward packet from VPN network to eth0 (my NIC). As root:
Code:
echo 1 > /proc/sys/net/ipv4/ip_forward
And I added the following entry to /etc/rc.local so it persists on restart.
Code:
iptables -t nat -A POSTROUTING -s 192.168.150.0/24 -o eth0 -j MASQUERADE
Some debugging tips for others
Simplest way to verify HTTP traffic is being forwarded is, after connecting to vpn from phone, go to www.whatismyip.com. Make sure it matches your phone.
If you are having trouble connecting to the VPN, watch the openvpn log for errors. "tail -f /var/log/openvpn/openvpn.conf"
After connecting, make sure you can ping from your home server to the phone.
From Server: "ping 192.168.150.10"
From Phone: Open Terminal Emulator and type "ping 192.168.150.1"
You can also validate the traffic is forwarding through VPN by using traceroute. You can test both forwarding and DNS
From Phone: Open Terminal Emulator, type
Code:
su
For no-DNS test first:
Code:
traceroute 74.125.115.104
For DNS test:
Code:
traceroute www.google.com
For each, do your tests on the cell network (NOT home wifi) and verify that the route passes through your vpn server and doesn't bypass it completely.
Lastly to make sure traffic is being piped, you can monitor VPN traffic from your openvpn server by typing:
Code:
tcpdump -i tun0
jvanbrecht:
Do you have any recommendations about dropped connections? I noticed while testing that sometimes my openvpn connection would drop and my phone browsing would immediately default to the direct default cell provider connection.
Of course if tethering, this could be very bad.
Any tips on ensuring that if VPN is enabled, but no connection, that it won't ever try and route around it?
would using any vpn do the same thing? or something making this special ? any one tested this ?
It's been a few weeks since I tried the openvpn app. Back then everything seemed to be working well. But I tried again today and am having problems.
- I can access everything fine via vpn if my phone is connected to my local wifi where the vpn server resides.
- I can access IP addresses (e.g. the ip address of google.com) if connected to vpn via AT&T's 3G network
- I CANNOT access websites by their name (e.g. www.google.com) anymore.
It seems the DNS forwarding over VNC is messed up. Any tips on what the problem could be?
I still have the same settings as above, e.g. push "dhcp-option DNS 192.168.150.1"
Is it possible I need to do any additional configuration on my phone?
Is it possible to replace my router DNS address with a public one like google's "8.8.8.8" or "4.2.2.2"?
Any tips greatly appreciated!
Deleted. Please ignore. Still having issues.
So I had the opportunity to play around with my config (listed above) a bit more this evening. I was at a location where I had good external WiFi (Panera) along with 3G.
If I connect from my phone to my home VPN server over EXTERNAL WIFI (Panera), I have no problems with VPN. everything works flawlessly.
If I connect from my phone to my home VPN server over AT&T 3G network, it fails. Essentially it can't resolve any DNS queries. I can type in a website's IP address and surf that way, but I can't say type in "www.cnn.com" and get a page to load.
For the latter, when I watch the web queries using "tcpdump -i tun0", I see the requests go out from my phone to the websites, but they don't come back. For example, I see:
"192.168.150.10 > a.b.c.d (www.cnn.com)",
but I don't see:
"a.b.c.d (www.cnn.com) > 192.168.150.10"
Is it possible that AT&T is somehow blocking VPN via DNS? At first I thought my openvpn dns settings were messed up ... but it works across external wifi no problem.
---------- Post added at 01:24 AM ---------- Previous post was at 01:07 AM ----------
For those that are interested in the future, I think I narrowed down the issue:
It seems VPN connectivity is dependent on the AT&T Access Point Network (APN)
By default for my Skyrocket I was on the AT&T PTA APN wit settings:
Code:
APN: pta
MMSC: http://mmsc.mobile.att.net
MMS proxy: proxy.mobile.att.net
MMS Port: 80
...
I then switched to what is called the "AT&T Expanded" APN with settings:
Code:
APN: wap.cingular
User Name: [email protected]
(rest of settings somewhere here on xda ...)
... and that one worked perfectly.
I switched back and forth a few tiimes to confirm. It seems on pta, I can't resolve DNS over VPN. For the wap.cingular, I have no problems.
Anyone else can confirm this is most likely the issue I am seeing and that it can possibly make sense?

Problem with VPN tether gateway setup

I have a G930F running Superman ROM rooted on MM with a ported XAA CSC. I have set it up to run a VPN gateway using iptables and ip route. I am able to get tethered devices to connect to the Internet through the VPN if I manually set the IP addresses and DNS servers on the clients connecting. I do however have some devices that do not have the ability to manually set the IP and DNS servers and it's also a pain to set every device up manually. I ran a Wireshark capture and found several ARP requests not being responded to from dhcpd/dnsmasq trying to hand out ip addresses to the clients. My goal is to get DHCP up and running on wlan0 to hand out IP and DNS configuration. I suspect it is not working due to the nature of the changes I've made with iptables and ip route. I'm thinking the dhcp is being forwarded to the tun0 interface. My question is how to exclude the DHCP from being forwarded to the tun0 interface... Or if someone else can come up with a more elegant solution to my problem, as I'm currently reading up on ip and iptables syntax and commands and my current knowledge is fairly basic. The process I'm using to connect my tethered devices is as follows: connect VPN, turn on tether, run commands listed below to connect the wlan0 and tun0 interfaces and connect clients to the phone after manually setting the IP and DNS.
Code:
su
iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -A FORWARD -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE
ip rule add from 192.168.43.0/24 lookup 61
ip route add default dev tun0 scope link table 61
ip route add 192.168.43.0/24 dev wlan0 scope link table 61
ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61
Any help would be greatly appreciated!
SystematiQ said:
Any help would be greatly appreciated!
Click to expand...
Click to collapse
Did you ever get this to work nicely? I am very intrigued.
Also, what VPN software are you using? I am using NCP which does most of what I want, though it is frustrating that I can't programmatically control connection/disconnection/profile selection nor even get it to connect at boot.

How to access wifi hotspot on phone with active VPN connectio?

I have to access the Internet through my phone data connection, from both Windows 10 laptop and Android 6.0.1 tablet. Both devices can connect fine to the wifi hotspot and they can use the Internet. However, if I connect the VPN client (Private Internet Access), neither the Windows 10 laptop, nor the Android tablet can connect anymore. If they were already connected before activating VPN, Internet access stops on both devices. The OnePlus One phone is rooted.
I googled for a solution and I found something with using iptables. The following commands should be pasted in a terminal window under root:
iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -I FORWARD -j ACCEPT
iptables -t nat -I POSTROUTING -j MASQUERADE
ip rule add from 192.168.43.0/24 lookup 61
ip route add default dev tun0 scope link table 61
ip route add 192.168.43.0/24 dev wlan0 scope link table 61
ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61
After these commands, the Windows 10 laptop can access the Internet, even if the VPN connection is active. However, the traffic from the laptop doesn't go through the VPN connection on the phone. If I check the IP address at whatismyip.com from the laptop, I get the T-Mobile ip address. If I do the same thing from the phone, I get the PIA server ip address.
Unfortunately, this solution does not work for the Android tablet. If already connected to the wifi hotspot, before activating VPN on the phone, Internet access stops. If I try to connect the tablet after activating VPN, it gets stuck in "obtaining IP address".
It seems that somehow, the Windows DHCP client knows how to access the DHCP server running on the phone (at 192.168.143.1). However, the request from the Android tablet is probably sent to the Internet, and does not reach the DHCP server (or the DNS server.) I suspect the local network (192.168.143.0/24) should be somehow excluded in iptables, but I don't know how to do that. Also, I'm not sure if I exclude it, the connection from Windows laptop will be affected.
So my main question is:
Is there a solution to access the wifi hotspot on the phone while VPN is active, from BOTH Windows and Android devices?
My second question is:
Is there a solution to direct the network traffic coming from the devices connected to the wifi hotspot, THROUGH the VPN connection running on the phone?
XDA:DevDB Information
Tethering with active VPN connection, Kernel for the OnePlus One
Contributors
alanPr
Kernel Special Features:
Version Information
Status: Testing
Created 2018-07-09
Last Updated 2018-07-09

Categories

Resources