Networking Notes

Networking Over Usb Aka Reverse Teethering

when i don't have access to a wireless network, such as at work, i'd like to connect my phone to my computer and use my computer's Internet connection.

On Linux Computer, setup a bridge:

# usb0 is the new network intreface
# eth0 is the main interface connected to internet (or a gateway)
sudo ifconfig eth0
sudo ifconfig usb0
sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo brctl addif br0 usb0
sudo ifconfig br0 up
sudo dhclient br0

On windows, Bridge the 2 network interfaces

Setup usb0 interface of your phone. You have to options:
1. From your computer, execute:
./adb shell netcfg usb0 dhcp
2. Or in a root terminal on your phone, type:
netcfg usb0 dhcp

You should now be able to connect to Internet on your phone using your computer's Internet connection.

Try to do a ping to be sure !


To shut down the reverse-tethering, first unbridge interfaces on your computer:

sudo ifconfig eth0 down
sudo ifconfig usb0 down
sudo ifconfig br0 down
sudo brctl delbr br0
sudo ifconfig eth0 up
sudo dhclient eth0

Then on your phone, uncheck the USB Tethering option !

On laptop, I'm using following script on laptop after enabling USB tether in Settings > Wireless & Networks > Tethering to setup default route on Android through laptop's network and provide NAT for it.
#!/bin/sh -x

sudo id

android=`adb shell ip addr list usb0 | grep 'inet ' | sed 's/^ *//g'`

a_ip=`echo $android | cut -d" " -f2 | cut -d/ -f1`
c_ip=`echo $a_ip | cut -d. -f-3`.1
netmask=`echo $android | cut -d" " -f4`

echo "Android $a_ip netmask $netmask -> $c_ip"

sudo ifconfig usb0 $c_ip netmask $netmask up
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -s $a_ip -o br0 -j MASQUERADE

adb shell ip route add default via $c_ip
adb shell setprop net.dns1

adb shell ping -c 1 $c_ip
ping -c 1 $a_ip

Compile ettercap 0.7.4 on Ubuntu

  • Download ettercap-0.7.4.tar.gz and unzip it
  • Download ettercap-NG-0.7.3.tar.gz, unzip it and copy utils\etterfilter\ef_grammar.h to the same folder in the ettercap-0.7.4 distribution
  • Get all the prerequisites

sudo aptitude install libpcre3-dev libtoolize autoconf bison libpango1.0-dev libatk1.0-dev libgtk2.0-dev libnet-dev libpcap-dev

  • Compile and install

sudo make install

All done. If you have a restrictive umask, open up the config folder

sudo chmod 755 /usr/local/share/ettercap/

Wireshark filter to hide broadcast traffic

eth.type == IP and (not (eth.addr == ff:ff:ff:ff:ff:ff||eth.addr contains 01:00:5e))

Eliminates ethernet broadcast,multicast and not IP based traffic

Increasing wireless range indoors

Some buildings do not allow your signal to pass through very well. The usual reason for this is foil-clad plasterboard or insulation. In an effort to insulate buildings and keep heat in, new plasterboard is foil clad to reflect infrared energy back into the room. However this means you effectively have huge metal sheets stopping all radio waves, so mobile phones, baby monitors, audio radios, and WiFi will all have problems with signal. Doors and windows usually allow wireless to pass through nearly unaffected, so positioning your antennas so the signal lines up through these openings will help. Also, you need to consider using a proper CAT5 cable between the points since the speed and reliability of this is far better. If you need wireless coverage, consider using more than one Access Point but wire them with network cable rather than attempting WDS repeater mode. Also, the WRT54G has a number of excellent 9 dB and 12 dB RP-TNC antennas available on eBay.

For transmission between floors, remember that the signal radiates away perpendicular 90 degrees from the antenna. This means that you can angle your signals up or down simply by angling the antennas, ideally so that both devices' antennas face each other on the same plane. For example, to broadcast directly upwards, point the length of the antennas used flat down. Also, on dual antenna routers, you can have one angled for upstairs and one for downstairs on the same device thereby giving each floor a targeted signal.

How can I increase range outdoors?

The most important thing for making your signal go far outside is height! The higher in the building you position your radio the further its signal will travel. Even a standard indoor unit with standard antennas can be used from 600 m (1,968 feet) away! To go farther you need to start using better antennas, the Access Point would work well with a 7 dB mounted just above roof height, this will give you a good 600 m (1,968 feet) to 1500 m (4,921 feet), it goes further in open areas and less far in built up areas. It's important to match the gain and height of your antenna to how far away you wish to receive your signal. You may end up picking up signals that you would be better off not being able to see. Also the use of too much height with a 12 dB antenna would mean your signal does not really come back to ground level for several kilometers past where you wish to use it. The effect of this is that it seems your signal is weak and does not go very far. This is an illusion: The signal could be going way over your head. A lesser gain antenna at a lower height would yield a far stronger local signal and immunity for interference from far away stray signals.

How do I read signal and noise ratings?

These numbers are given in decibels (dB) and are expressed as negative numbers. So, a lesser number, like -40 dB, represents more strength than -70 dB. The values are logarithmic. A signal amplitude change of 3 dB is equivalent to a factor of two; 10 dB is a factor of ten.

Based on this Forum-post

Signal: A low negative number is good (-40 is good, -98 is bad, mathematically -10 is higher than -98.)

Noise: A high negative number is good (-98 is good, -40 is bad, -70 would be pretty bad in the real world)

SNR: High is good (should be the same as difference between noise and signal, a difference of 20 would be great, a difference of 1 may barely work)

Signal Quality: High is good (somewhat like SNR but indexed to 100 with noise as the base, percentage of the best theoretical ideal quality in regards to your local-noise)

Examples would be: Signal Noise SNR Signal Quality -82 -98 16 14%

Signal - Noise = SNR

 -82  -  -98  = 16

Signal / Noise * SNR = Signal Quality

 -82  /  -98  * 16  = 13.4%

Typically, noise will be -92 which means you should get a connection with a signal as low as -92. However, expecting to hold a good connection with a signal less than -85 (e.g. -90), is expecting too much. The signal can be improved by -3 dB by doubling the power setting at the transmitting radio, e.g., 100 mW increased to 200 mW would improve your signal from -85 to -82. Antennas with increased gain will also help. Say you had the standard 3 dB antenna and changed it for a 12 dB antenna, that's a 9 dB increase, so your signal would increase from -82 to -73 which would be an excellent signal, probably capable of 54 Mbps. Using the term excellent in terms of running a WISP, it would probably be only 3 bars on a 5 bar signal strength meter. Don't worry if, as a WISP your signal quality is low, like 14%. It's not really a problem since -82 is considered acceptable.

@TechnicalNotes @Networking