Difference between revisions of "USB Internet"

From postmarketOS
Jump to: navigation, search
(Added syntax highlighting)
Line 1: Line 1:
USB Internet
+
You can enable internet through the USB cable when WiFi doesn't work yet on your device. For this to work you set your host machine as gateway for your phone and let your host machine do network address translation for the phone.
Enable Internet on your device by using a usb cable (when wifi does not work).
 
  
On your phone:
+
==== On your phone: ====
  
X are your pc usb ip address last numbers you will find in your pc's network manager.
 
  
 
<syntaxhighlight lang="shell-session">
 
<syntaxhighlight lang="shell-session">
$ sudo route add default gw 172.16.42.x
+
$ sudo route add default gw 172.16.42.2
$ sudo nano /etc/resolv.conf
+
$ echo "nameserver 8.8.8.8" >> /etc/resolv.conf
 +
Substitute 8.8.8.8 for your own internal DNS server if you want.
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Delete and write instead your router ip address (nameserver 192.168.1.1) or dns server address (nameserver 8.8.8.8)
+
==== On the host machine: ====
 
 
On your pc:
 
  
 
<syntaxhighlight lang="shell-session">
 
<syntaxhighlight lang="shell-session">
Line 21: Line 18:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
You are done! Now try to ping someone!
+
This will enable IPv4 forwarding on your host machine which basically lets it function as a router. The postrouting command will make the kernel on the host translate the packets between the phone network
 +
and your normal network on the host machine.
 +
 
 +
You can now verify the internet connection on your phone my pinging something

Revision as of 07:04, 23 September 2017

You can enable internet through the USB cable when WiFi doesn't work yet on your device. For this to work you set your host machine as gateway for your phone and let your host machine do network address translation for the phone.

On your phone:

$ sudo route add default gw 172.16.42.2
$ echo "nameserver 8.8.8.8" >> /etc/resolv.conf
Substitute 8.8.8.8 for your own internal DNS server if you want.

On the host machine:

$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward > /dev/null
$ sudo iptables -P FORWARD ACCEPT
$ sudo iptables -A POSTROUTING -t nat -j MASQUERADE -s 172.16.42.0/24

This will enable IPv4 forwarding on your host machine which basically lets it function as a router. The postrouting command will make the kernel on the host translate the packets between the phone network and your normal network on the host machine.

You can now verify the internet connection on your phone my pinging something