Use OpenWRT Router For Lan Forwarding

TurnToJPG -->

USB Ethernet

Insert the USB Ethernet Dongle into the Ubuntu14.04, it will be automatically recognized and initialized.

$ dmesg | tail 
    [10323.307662] asix 2-2.2:1.0 eth1: register 'asix' at usb-0000:00:1d.7-2.2, ASIX
    AX88772B USB 2.0 Ethernet, 84:xx:xx:xx:xx
    [10323.307704] usbcore: registered new interface driver asix
    [10324.285425] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
$ ifconfig eth1
    eth1      Link encap:Ethernet  HWaddr 84:xx:xx:xx:

Be care to see the udev rules definition:

$ cat /etc/udev/rules.d/70-persistent-net.rules 

# USB device 0x:0x (asix)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="84:xx:xx:xx:xx",
ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

IP Configuration

Add the following items into the network configuration file:

# vim /etc/network/interfaces 
    # usb network eth1
    allow-hotplug eth1
    iface eth1 inet static

Now restart the network, to see the ethernet has been enabled.

DHCPD Configuration

Add following configuration to the /etc/dhcp/dhcpd.conf:

### this is for USB NET

subnet netmask {
# --- default gateway
option routers;
# --- Netmask
option subnet-mask;
# --- Broadcast Address
option broadcast-address;
# --- Domain name servers, tells the clients which DNS servers to use.
option domain-name-servers,;
option time-offset 0;
default-lease-time 1209600;
max-lease-time 1814400;

IPtables and dhcpd

Add following items into the ~/.config/awesome/rc.lua

autorunApps =
-- "pidgin",
"sudo iptables -t nat -A POSTROUTING -s ! -d  -j MASQUERADE",
"sudo iptables -t nat -A POSTROUTING -s ! -d -j MASQUERADE" 
"sudo dhcpd wlan0 eth1",

Now everytime we reboot the system, it will automatically start the dhcpd server and let OpenWRT as the access Point.

Kernel IPV4 Forwarding

Check the configuration:

# sysctl -a | grep forward

Enable the forwarding manually:

# sysctl net.ipv4.ip_forward=1

added it into system startup:

# vim /etc/sysctl.d/30-ipforward.conf