0

I finally managed to setup an access point on my WiFi card using hostapd and dnsmasq. I did it in this order:

1) Configure hostapd and dnsmasq:

nano /etc/hostapd/hostapd.conf

nano /etc/dnsmasq.conf

Contents of hostapd.conf:

interface=wlan1mon
driver=nl80211
ssid=o2wlan69
hw_mode=g
channel=6
macaddr_acl=0
ignore_broadcast_ssid=0

Contents of dnsmasq.conf:

interface=wlan1mon
dhcp-range=192.168.1.2,192.168.1.30,255.255.255.0,12h
dhcp-option=3,192.168.1.1
dhcp-option=6,192.168.1.1
server=8.8.8.8
log-queries
log-dhcp
listen-address=127.0.0.1

2) These are two of the four lines which I don't know exactly what they do:

ifconfig wlan1mon up 192.168.1.1 netmask 255.255.255.0

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

3) Start the services:

dnsmasq -C /etc/dnsmasq.conf -d

hostapd /etc/hostapd/hostapd.conf

4) And here are lines 3 and 4 which I don't know exactly what they do:

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

I know that iptables is used to alter block or reroute traffic coming to and from the device and I know that you can assign netmasks and IP addresses to networking devices with ifconfig. I also know how a netmask affects the local IP range but it is not clear to me how these commands help my access point share an internet connection between my wlan1mon and eth0 interface. In addition, why do I have to run the ifconfig and the route command?

1 Answer 1

2
ifconfig wlan1mon up 192.168.1.1 netmask 255.255.255.0

This command tells your computer to enable the network device wlan1mon (your WiFi interface) and assign the IP Address 192.168.1.1 to it (with the subnet 192.168.1.0/24), so that it may send/receive networking packages.

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

This command tells the computer to send every package that has a recipient in the subnet of 192.168.1.1/24 through 192.168.1.1 (I'm unsure if this command should be run on the computer that forwards, as routes are only needed for the connecting clients as far as I am concerned. And as you already have a set up DHCP server, this route should be added automatically on those clients.)

iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE

This command instructs the computer to correctly "masquerade" the IP of incoming/outgoing packages (Network Address Translation) in the POSTROUTING chain on eth0. Basically, it assigns the computer's IP-Address to every outgoing package (so that outside computers are able to send a response) and readdresses the incoming packages for the appropriate host inside your network.

iptables --append FORWARD --in-interface wlan1mon -j ACCEPT

This command allows incoming packages from wlan1mon to be forwarded in the first place. This means, that the forwarding computer is allowed to process and forward those network packages (even) if the recipient is someone else.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .