How To Set Up PC as a Router / Bridge in Different OS's

How To Set Up PC as a Router / Bridge in Different OS's

2012-04-24. Category & Tags: Soft&Skills Soft&Skills

See also: /iptables

FreeBsd 7 Local Router (Like a Switch ???) #

(local only, no NAT)
vim /etc/rc.conf

ifconfig_em0="inet netmask"
ifconfig_em1="inet netmask"

notice: will get route problem if using the same net-addr.

  • permanent
# vim /etc/sysctl.conf
# reboot
  • temp
sysctl net.inet.ip.forwarding=1
# or
echo 1 > /proc/sys/net/ipv4/ip_forward

// problem: ping test: could get reply since icmp packet 113. where are the first 112 packets???

FreeBsd 7 Bridge #

ref: shaper freeBsd-v7 : bridge

# vim /etc/rc.conf
ifconfig_bge0="inet netmask"
ifconfig_bridge0="addm em0 addm em1 up"
  • /etc/sysctl.conf

or, using cmd : sysctl net.inet.ip.forwarding=1;

Ubuntu 10.04~16.04 NAT #

NAT is mandatory for a router to route traffic between its clients and upper internet.

# /etc/sysctl.conf
net.ipv4.ip_forward = 1
# sysctl -p


# vim /etc/rc.local
iptables --table nat --append POSTROUTING --out-interface <outer-WAN>0 -j MASQUERADE
iptables --append FORWARD --in-interface <eth-inner-lan>1 -j ACCEPT

(here: for improved security)
restart networking:

service networking restart

We may want to and setup DHCP server, see here.

Ubuntu 10.04 Bridge #

firstly: sudo apt-get install bridge-utils

type 1: named / ip-ed bridge #

# vim /etc/rc.conf
auto br0
iface br0 inet static
bridge_ports all

type 2: anonymous bridge (bridge without ip) #

# vim /etc/rc.conf
auto br1
iface br1 inet manual
    bridge_ports eth1 eth2
    #bridge_ports all
    bridge_maxwait 0


Openwrt NAT #

Similar to Ubuntu 10.04 NAT, but inserting (instead of appending) iptables rules due to the already existing rules.

sysctl -w net.ipv4.ip_forward=1 # or: echo 1 > /proc/sys/net/ipv4/ip_forward
## confirm this is enabled by default in the file: /etc/sysctl.conf

iptables --table nat --insert POSTROUTING 1 --out-interface eth0 -j MASQUERADE
iptables --insert FORWARD 1 --in-interface wlan0 -j ACCEPT
# iptables rules can be written to file: /etc/rc.local

Maybe it can be done in a better way using wrt zone settings. Already spend a lot of time, will try next chance.

Change NIC (network interface card) name #

vim /etc/udev/rules.d/70-persistent-net.rules

Windows 7 #

netsh wlan set hostednetwork mode=allow ssid="<ssid_name>" key=<passwd_plain_text>

system echo:

The hosted network mode has been set to allow.
The SSID of the hosted network has been successfully changed.
The user key passphrase of the hosted network has been successfully changed.

netsh wlan start hostednetwork

system echo:

The hosted network started.

After sleep/hibernate, we need to start it again by netsh wlan start hostednetwork.

About the Wireless Hosted Network (Windows) - MSDN - Microsoft
How to set up Virtual Wifi in Windows 7

How to set up Virtual Wifi in Windows 7