RadarURL Dev Tips

[Centos] Create NAT using wifi connection

How create NAT using wifi card as WAN interface ? 
Simply way:
On my box I have two network interfaces eth0 and wlan0
In first step I add IP for my eth0 interface. I want create LAN using 10.10.1.X range. 
  su -
  ip addr add 10.10.1.1/24 dev eth0 
or set Ip for eth0 ‘permanently’:
  vi /etc/sysconfig/network-scripts/ifcfg-eth0


My file:
EVICE=”eth0”
HWADDR=”BC:AE:C5:60:A4:50”
NM_CONTROLLED=”yes”
BOOTPROTO=static
BROADCAST=10.10.1.255
IPADDR=10.10.1.1
NETMASK=255.255.255.0
NETWORK=10.10.1.0
ONBOOT=yes
TYPE=Ethernet


 Enable ip forwarding*:
vi /etc/sysctl.conf 
and set 1
# Controls IP packet forwarding
net.ipv4.ip_forward = 1

next
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
/sbin/service iptables save

Set up dhcp server

In my box I using Dnsmasq,lightweight, easy to configure DNS forwarder and DHCP server.

more info: http://thekelleys.org.uk/dnsmasq/doc.html

yum install dnsmasq
vi /etc/dnsmasq.conf 

Uncomment and add IP range for new LAN
dhcp-range=10.10.1.2,10.10.1.40,12h

And now i can connect switch or other box/notebook to my eth0 via standard ethernet cable :)
Show network interface throughput statistics with sar or bmon

sar -n DEV 1 3

*Other way to setup ip forward:
http://www.ducea.com/2006/08/01/how-to-enable-ip-forwarding-in-linux/