美文网首页Raspberry Pi
一步一步教你让raspberry pi 作为wifi使用

一步一步教你让raspberry pi 作为wifi使用

作者: hglfNg | 来源:发表于2019-02-14 13:34 被阅读36次

    一下所有说明都基于官方的发行版raspbian,根据官方文档和实践整理记录

    要达到的效果

    raspberry pi 组成局域网192.168.5.0/24,设备可以通过访问raspberry pi 的无线网络实现互访,对于外网访问请求通过有线接口转发(NAT)

    1. 更新源
    sudo apt update
    sudo apt upgrade
    
    1. 按照两个关键的软件包
    sudo apt-get install dnsmasq hostapd
    
    1. 为无线接口设置固定ip
    sudo vim /etc/dhcpcd.conf
    

    添加内容如下

    interface wlan0
        static ip_address=192.168.5.1/24
        nohook wpa_supplicant
    
    1. 设置dhcp
    sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig  
    sudo vim /etc/dnsmasq.conf
    

    编辑内容如下:

    interface=wlan0      # Use the require wireless interface - usually wlan0
      dhcp-range=192.168.5.100,192.168.5.200,255.255.255.0,24h
    
    1. 设置无线网络
    sudo vim /etc/hostapd/hostapd.conf
    

    编辑内容如下

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

    编辑hostapd配置指向我们之前的配置文件

    sudo vim /etc/default/hostapd
    
    DAEMON_CONF="/etc/hostapd/hostapd.conf"
    
    1. 设置流量转发
    sudo vim  /etc/sysctl.conf
    
    net.ipv4.ip_forward=1
    
    sudo iptables -t nat -A  POSTROUTING -o eth0 -j MASQUERADE
    
    sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
    

    编辑 /etc/rc.local 在 "exit 0" 这行前添加内容

    iptables-restore < /etc/iptables.ipv4.nat
    
    1. 重启

    相关文章

      网友评论

        本文标题:一步一步教你让raspberry pi 作为wifi使用

        本文链接:https://www.haomeiwen.com/subject/ftheeqtx.html