I’m trying to either make a bridge between eth0 (Usb modem) and wlan0 (Wifi Hotspot) or route all traffic from wlan0 to eth0.
Procedure:
Bridge won’t be successful if the interfaces already have an ip.
ip addr flush dev eth0 ip addr flush dev wlan0
Create the bridge and add the network.
brctl addbr br0 brctl addif br0 eth0
Start the wifi hotspot. At this point I can see the network with my phone.
hostapd /etc/hostapd.conf -B &
Assign the bridge an ip.
ifconfig br0 192.168.0.1
Start dhcp-server so my hotspot can automatically assign an ip address to the connected devices.
/etc/init.d/S80dhcp-server start
Reset my bridge.
ifdown br0 ifup br0
Configuration files
hostapd.conf:
interface=wlan0 bridge=br0 driver=nl80211 ctrl_interface=/var/run/hostapd ssid=My_Network dtim_period=2 beacon_int=100 channel=7 hw_mode=g max_num_sta=8 ap_max_inactivity=300
/etc/network/interfaces:
auto br0 iface br0 inet manual bridge_ports eth0 wlan0
/etc/dhcp/dhcp.conf
ddns-update-style none; option domain-name "google.com"; option domain-name-servers 8.8.8.8, 8.8.4.4; default-lease-time 600; max-lease-time 7200; authoritative; log-facility local7; subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.100 192.168.0.110; option broadcast-address 192.168.0.255; option routers 192.168.0.1; }
The dhcp-server returned OK but when I try to connect to the wifi hotspot I can’t get an ip. Any ideas on how to proceed?
Advertisement
Answer
I finally managed to get it done. I didn’t use bridge but iptables.
Just these two commands were enough:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.1/24 -j MASQUERADE
Here is the source of the answer with the explanation