Ubuntu 路由器接入点

Ubuntu 路由器接入点

我制作了一个 Ubuntu 接入点。该 AP 基于 Ubuntu 服务器 18.04。最初它可以工作,但过了一段时间(重启几次后)我总是可以连接到 AP,但我无法再访问互联网,也无法使用 SSH 终端(DHCP 可以工作,似乎是路由问题)。在物理连接到家庭路由器的 enp1s0 接口上执行 ping 操作可以工作。我使用此程序使 AP 工作(任何帮助都将不胜感激):

sudo apt update
sudo apt upgrade

软件包安装:

sudo apt install ifupdown
sudo apt install bridge-utils

网络接口配置:

sudo nano /etc/network/interfaces

auto lo
iface lo inet loopback

allow-hotplug enp1s0
iface enp1s0 inet static
address 192.168.1.4
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.1

allow-hotplug enp2s0
iface enp2s0 inet manual

auto wlp3s0
iface wlp3s0 inet manual

auto br0
iface br0 inet static
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
bridge_ports enp2s0 wlp3s0
bridge_stp off
bridge_fd 0
bridge_maxwait 0

删除 NETPLAN:

systemctl stop systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online

systemctl disable systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online

systemctl mask systemd-networkd.socket systemd-networkd networkd-dispatcher systemd-networkd-wait-online

apt-get --assume-yes purge nplan netplan.io

启用网络:

sudo systemctl unmask networking
sudo systemctl enable networking
sudo systemctl restart networking

DNS 服务器配置:

sudo nano /etc/systemd/resolved.conf
....
DNS=8.8.8.8 8.8.4.4
....

sudo systemctl restart systemd-resolved

启用 IP 转发:

sudo nano /etc/sysctl.conf

重启服务器:

sudo reboot

测试 DNS:

nslookup www.google.it

切入点:

数据包安装:

sudo apt install wireless-tools
sudo apt install hostapd

接入点配置:

sudo nano /etc/hostapd/hostapd.conf

interface=wlp3s0
driver=nl80211
bridge=br0
country_code=BO
ssid=APNAME
hw_mode=g
channel=10
logger_syslog=-1
wmm_enabled=1
macaddr_acl=0
auth_algs=1
wpa=2
wpa_passphrase=APPASSWORD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

接入点测试:

sudo hostapd /etc/hostapd/hostapd.conf

启用接入点服务:

sudo nano /etc/default/hostapd

DAEMON_CONF="/etc/hostapd/hostapd.conf"
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo systemctl status hostapd

DHCP 服务器:

软件包安装:

sudo apt install isc-dhcp-server
sudo nano /etc/default/isc-dhcp-server

INTERFACESv4="br0"
sudo nano /etc/dhcp/dhcpd.conf

option domain-name "domotica.org";
option domain-name-servers 8.8.8.8, 8.8.4.4;
ddns-update-style none;
authoritative;

subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.4 192.168.2.254;
option domain-name-servers 8.8.8.8;
option domain-name "domotica.org";
option subnet-mask 255.255.255.0;
option routers 192.168.2.1;
option broadcast-address 192.168.2.255;
option ntp-servers 192.186.2.1;
option netbios-name-servers 192.168.2.1;
option netbios-node-type 2;
default-lease-time -1;
max-lease-time -1;
}

启用 DHCP 服务器:

sudo systemctl start isc-dhcp-server

sudo systemctl enable isc-dhcp-server

路由:

sudo iptables -t nat -A POSTROUTING -o enp1s0 -j MASQUERADE 

sudo apt install iptables-persistent

Sae IPV4 和 IPV6

重启 HUB

相关内容