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

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

ifconfig_em0="inet 10.0.0.12 netmask 255.255.255.0"
ifconfig_em1="inet 10.0.1.13 netmask 255.255.255.0"

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

  • permanent
# vim /etc/sysctl.conf
net.inet.ip.forwarding=1
# 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 192.168.1.176 netmask 255.255.255.0"
cloned_interfaces="bridge0"
ifconfig_bridge0="addm em0 addm em1 up"
ifconfig_em0="up"
ifconfig_em1="up"
defaultrouter="192.168.1.168"
nameserver 8.8.8.8
firewall_enable="YES"
firewall_type="open"
  • /etc/sysctl.conf
net.inet.ip.forwarding=1

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

and:

# 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
    address 192.168.1.2
        network 192.168.1.0
        netmask 255.255.255.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
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

ref

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
ref

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.

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