Introduction to the

You can configure HostAPd, UDHCPD, sySCtl, iptables, and interfaces to enable the wireless router function through forwarding.

1. Install HostAPD and UDHCPD

Run the apt-get update command to update resources

Installation command: apt-get install udhcpd

Note: Under normal circumstances, the system will come with ithostapdIf not, you can install itapt-get install hostapd

If the resource update fails:

Replace domestic apt-get source:

Backup: cp/etc/apt/sources list/etc/apt/sources list. Bak

Replacement: sed -i ‘s / : \ \ / \ \ \ (. *) / / : \ \ / < source address > / g’/etc/apt/sources list

Update: apt-get update

< source address >

Tsinghua university: mirrors.tuna.tsinghua.edu.cn/ubuntu-ports

Ali: mirrors.aliyun.com/ubuntu

2. Edit the configuration file

Udhcpd (Dynamic IP Assignment Service) :

vi /etc/udhcpd.conf

start		192.16830.20.	#default: 192.168. 020.
end		192.16830.254.	#default: 192.168. 0254.
interface	wlan0		#default: eth0
remaining	yes		#default: yes
opt	dns	8.88.8. 114.114114.114.
option	subnet	255.255255.. 0
opt	router	192.16830.1.
Copy the code

vi /etc/default/udhcpd

Comment out the

# DHCPD_ENABLED="no"
Copy the code

Hostapd (Hot Service) :

vi /etc/hostapd.conf

Interface =wlan0 driver= NL80211 SSID =WIFINAME # hw_mode=g channel=6macaddr_acl=0auth_algs=1ignore_broadcast_ssid=0wpa=2wpa_passphrase=12345678# Wifi password, no less than8A wpa_key_mgmt = WPA wpa2-psk wpa_pairwise = TKIP rsn_pairwise = CCMPCopy the code

vi /etc/default/hostapd

uncomment

DAEMON_CONF="/etc/hostapd.conf"
Copy the code

Sysctl (enable forwarding) :

vi /etc/sysctl.conf

uncomment

net.ipv4.ip_forward=1 #1Open,0Shut downCopy the code

Note: Sysctl can modify kernel parameters to temporarily enable data forwarding: sh -c “echo 1 > /proc/sys/net/ipv4/ip_forward”

Iptables (configuring firewall rules) :

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Sh -c “iptables-save > /etc/iptables.ipv4. NAT “(save to /etc/iptables.ipv4.nat)

Interfaces (configured as static IP for wlan0) :

vi /etc/network/interfaces

Append the following to the end

Allow-hotplug eth0 # LAN port configuration hot update iface wlan0 inetstaticStatic IP address for port wlan0192.16830.1. 
    netmask 255.255255.. 0\
up iptables-restore < /etc/i# enable firewall rules in /etc/iptables.ipv4. NATCopy the code

Note: Temporarily set the IP address command: ifconfig wlan0 192.168.30.1

3. Start the command

service hostapd start

service udhcpd start