生于忧患,咸鱼安乐
Toggle navigation
Home
About Me
Archives
Tags
树莓派4体验ubuntu20.04之搭建WiFi热点
树莓派
Linux
Ubuntu
计算机网络
软路由
2020-08-16 00:20:15
1819
0
0
squarefong
树莓派
Linux
Ubuntu
计算机网络
软路由
想拿树莓派搭热点试试看,玩了一下OpenWrt,发现一旦进不了luci就会很麻烦。想起几个月前就有新闻的Raspberry Pi OS的64位,去看看怎么样了,发现还没发布。看到Ubuntu有arm 64的image,顺手体验一下。 # 0. 环境 树莓派4, 4G版本 系统镜像[Ubuntu server 20.04](https://ubuntu.com/download/raspberry-pi/) **目的**:有线网口作为wan口连接到互联网,无线网口作为热点发射WiFi。 # 1. 装系统 ## 安装 下好的镜像格式是img.xz,解压后用Win32DiskImager烧录。也可以直接不解压,使用balena-etcher烧录。烧录完成后插电就能开机,第一次开机会自动运行一些东西,当屏幕出现Ubuntu Login即可登录。默认用户名和密码都是ubuntu。如果出现登录失败,是正常现象,等一两分钟就好了。 ## 换源 默认的Ubuntu镜像源在海外,速度太慢了,这里可以换成清华源 ```bash sudo sed -i 's/http:\/\/ports.ubuntu.com\/ubuntu-ports/https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu-ports/g' /etc/apt/sources.list ``` ## 关闭自动更新 修改配置文件/etc/apt/apt.conf.d/10periodic,将所有值改为0(实际上也就Update-Package-Lists是1) 或者使用命令替换: sudo sed -i 's/\"1\"/\"0\"/g' /etc/apt/apt.conf.d/10periodic ## 切换时区 ``` sudo timedatectl set-timezone Asia/Shanghai ``` # 2. 搭建WiFi热点 首先,安装所需要的包```sudo apt install hostapd dnsmasq```,然后将下面的文件分别更改为后面列出的内容。下面命令无特殊说明都在root权限下执行。 ## 配置ap (1) ```vim /etc/hostpapd/hostapd.conf``` 把下面的内容复制粘贴进去,注意更改wifi名称和密码 interface=wlan0 driver=nl80211 ssid=raspberry pi #wifi名称 hw_mode=g channel=7 macaddr_acl=0 auth_algs=3 ignore_broadcast_ssid=0 wmm_enabled=1 ieee80211n=1 ht_capab=[HT40-][SHORT-GI-20][SHORT-GI-40] wpa=2 wpa_passphrase=123456 #wifi密码 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP (2) ```vi /etc/default/hostapd``` DAEMON_CONF="/etc/hostapd/hostapd.conf" ## 配置dns服务器 (1) ```vim /etc/dnsmasq.conf``` port=53 resolv-file=/etc/resolv.dnsmasq.conf server=223.5.5.5 listen-address=127.0.0.1,192.168.5.1 dhcp-range=192.168.5.50,192.168.5.150,12h dhcp-option=3,192.168.5.1 dhcp-option=6,192.168.5.1 cache-size=1024 conf-dir=/etc/dnsmasq.d (2) ```vim /etc/resolv.dnsmasq.conf``` nameserver 114.114.114.114 nameserver 223.5.5.5 nameserver 223.6.6.6 (3) ```vi /etc/resolv.conf``` nameserver 127.0.0.1 ## 其他配置 配置ip和转发 ``` ip addr add 192.168.5.1/24 dev wlan0 echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf && sysctl -p iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE ``` WiFi地域码 ``` iw reg set CN ``` ## 启动服务 ``` systemctl disable systemd-resolved systemctl stop systemd-resolve sudo systemctl unmask hostapd systemctl start hostapd systemctl enable hostapd systemctl start dnsmasq systemctl enable dnsmasq ``` # 3. 设置开机自启动 (1) ```sudo vim /usr/bin/autoHotspot``` 粘贴以下内容 #!/usr/bin/bash sleep 16 ip addr add 192.168.5.1/24 dev wlan0 iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iw reg set CN /usr/sbin/hostapd -B -P /run/hostapd.pid -B /etc/hostapd/hostapd.conf 保存退出后执行```chmod +x /usr/bin/autoHotspot``` (2)```sudo vim /lib/systemd/system/hostapd.service``` 把ExecStart后面更改为```/usr/bin/autoHotspot```
Pre:
树莓派4体验ubuntu20.04之编译安装Kodi
Next:
UOS个人版体验
0
likes
1819
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus
Table of content