4

On my linux computer I have an external wlan adapter which is connected wirelessly to internet (an access point). Now I want to connect my linux computer via ethernet cable to a new ddwrt router. This ddwrt router should now "get" internet from my linux computer, so that my linux computer is acting like a internet sharing box.

INTERNET <- over wlan (wlan0) -> LINUX COMPUTER <- ethernet eth0 -> DDWRT Router

Anyone should now be able to connect wirelessly to the ddwrt router to get internet. How should I configure my linux computer to make it work? Thanks!

John
  • 41
  • 1
  • 2

1 Answers1

4

If I understand what you're afer, you want the following:

You <-> Home systems <-> DDWRT Router <-> Linux Box <-> Internet

If so then you'll need to do a couple of things on your Linux laptop. Depending on what distro you're using the steps will be slightly different. My steps are for a Fedora Redhat distro.

% vim /etc/sysconfig/network-scripts/ifcfg-eth0

Contents of ifcfg-eth0:

DEVICE=eth0
BOOTPROTO=none
BROADCAST=xx.xx.xx.255  # Optional Entry
IPADDR=xx.xx.xx.xx
NETMASK=255.255.255.0   # Provided by the ISP
NETWORK=xx.xx.xx.0     # Optional
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
GATEWAY=xx.xx.xx.xx # The linux laptop's lan ip

Flush your iptables:

% iptables --flush
% iptables --table nat --flush
% iptables --delete-chain
% iptables --table nat --delete-chain

Now configure masquerading:

% iptables --table nat --append POSTROUTING --out-interface wlan0 -j MASQUERADE
% iptables --append FORWARD --in-interface eth0 -j ACCEPT

Configure NAT forwarding:

% echo 1 > /proc/sys/net/ipv4/ip_forward

Make this permanent, by adding the following line:

% vim /etc/sysctl.conf
net.ipv4.ip_forward = 1

Restart iptables service:

% service iptables restart

These are the steps from my memory so you may run into a issue here or there but they're pretty much all the steps you'll need to setup a Linux box as a router/switch.

NOTE: You'll also need to setup any devices on the LAN side so that their default route is the IP address of the Linux boxes LAN connection (eth0).

Resources

slm
  • 363,520
  • 117
  • 767
  • 871