How to connect new user to hotspot while vpn running?


Question

I'm running marshmallow (6.0.1) rooted. I run the following commands



iptables -F

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


So I can tether the vpn connection. My problem is once tethered no new client can connect it stays at obtaining iptables address. How can I fix this?


Answer


Normally in plain hotspot mode (without VPN setup), clients will get
an IP address from the phone's DHCP server.



However, when the OpenVPN client is running, by default it is
redirecting all traffic to the OpenVPN server, meaning any client
traffic is also being redirected. Hence, the clients aren't talking to
the phone's DHCP server any more - they are talking to the OpenVPN
server, and if that doesn't provide an IP address via DCHP then the
clients connection attempts will "hang".




There are possible workaround to keep tethering functionality on other connecting clients:




  1. Using postrouting and forwarding rules



You can just add just post-routing and forwarding rules i.e



iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -A FORWARD -j ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE


(this is the solution I'm using currently),







  1. Setup IP addresses manually




    • You may need to assign other clients IP manually (static IP
      address) to bypass DCHP server.








  1. Exclude hotspot subnet from tunnel





  • The fix is to identify the subnet used by the hotspot service and
    manually add it to Excluded Networks for the connection. i.e
    192.168.43.0/24.


  • Now when the tunnel is initiated the hotspot subnet is always excluded from routing through the tunnel regardless of startup
    sequence and tethering always works.





or simply excluding 192.168.43.0/24 (and including 0.0.0.0/0) rules from iptables.



Acknowledgements




Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes