ubuntu中怎么利用hostapd搭建無(wú)線路由

ubuntu中怎么利用hostapd 搭建無(wú)線路由,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

創(chuàng)新互聯(lián)是一家專(zhuān)業(yè)提供廣南企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、HTML5建站、小程序制作等業(yè)務(wù)。10年已為廣南眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。

因?yàn)楣镜腎P不固定,不能使用靜態(tài)IP來(lái)配置樹(shù)莓派的 ap 模式,只能固定一個(gè)IP到無(wú)線網(wǎng)卡上。如果是固定IP,使用netplan就足夠了。

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.0.1/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]
  wifis:
    wlp58s0:
      dhcp4: yes
      dhcp6: no
      access-points:
        "your-wifi-SSID-name":
          password: "your-wifi-password"

我使用的是 client <-> DNSmasq + hostapd - wlan0 -> iptables nat -> eth0

hostapd

hostapd 配置: /etc/hostapd/hostpad.conf

interface=wlan0
driver=nl80211
ssid=MyWiFiNetwork
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

修改 hostapd 默認(rèn)加載配置文件: /etc/default/hostapd

DAEMON_CONF="/etc/hostapd/hostapd.conf"

重新加載 systemd 服務(wù),重啟 hostapd

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd

dnsmasq

dnsmasq 上游 dns 配置: /etc/resolv.dnsmasq

nameserver 223.5.5.5
nameserver 8.8.8.8

dnsmasq 配置: /etc/dnsmasq.conf

listen-address=192.168.89.1
resolv-file=/etc/resolv.dnsmasq
interface=wlan0
dhcp-range=192.168.89.2,192.168.89.20,255.255.255.0,24h

取消 systemd-resolv 配置:/etc/systemd/resolv.conf,取消綁定 53 端口:

[Resolve]
DNS=192.168.89.1
DNSStubListener=no

修改 dnsmasq systemd service 文件: /lib/systemd/system/dnsmasq.service , 讓 dnsmasq 可以綁定固定 IP

[Unit]
After=network-online.target
Wants=network-online.target

重新加載服務(wù),重啟服務(wù)

systemctl daemon-reload
systemctl restart  systemd-resolved.service
systemctl restart dnsmasq

配置網(wǎng)絡(luò)

netplan 文件: /etc/netplan/50-cloud-init.yaml

network:
    ethernets:
        eth0:
            dhcp4: true
            optional: true
        wlan0:
            dhcp4: false
            addresses:
            - 192.168.89.1/24
    version: 2

應(yīng)用配置:

netplan apply

NAT 配置

配置內(nèi)核允許轉(zhuǎn)發(fā):/etc/sysctl.d/99-sysctl.conf 新增:

net.ipv4.conf.all.forwarding=1

應(yīng)用配置:

sysctl -p

iptables:

sudo iptables -t nat -A POSTROUTING -s 192.168.89.0/24 -o eth0 -j MASQUERADE

安裝 iptables-persistent 保存iptables, 開(kāi)機(jī)啟動(dòng)自動(dòng)加載:

sudo apt install iptables-persistent

安裝后會(huì)交互詢(xún)問(wèn)是否保存當(dāng)前的iptables,也可以手動(dòng)保存:

sudo su -c 'iptables-save > /etc/iptables/rules.v4'

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。

網(wǎng)站題目:ubuntu中怎么利用hostapd搭建無(wú)線路由
標(biāo)題URL:http://bm7419.com/article44/ijpehe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)、企業(yè)建站、網(wǎng)站制作、關(guān)鍵詞優(yōu)化、軟件開(kāi)發(fā)、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司