ubuntu命令行配置wifi,不使用NetworkManager和netplan

ubuntu 18.04 命令行配置wifi,不使用NetworkManager和netplan

  • 配置Ethernet
  • 配置WIFI

配置Ethernet

还是老办法,直接修改/etc/network/interfaces

auto eth0
iface eth0 inet static
pre-up ifconfig eth0 hw ether 4a:90:e9:67:00:00
address 192.168.8.10
netmask 255.255.255.0
#gateway 192.168.8.1
#dns-nameservers 114.114.114.114

配置WIFI

  1. 先禁用NetworkManager
sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager
sudo systemctl stop NetworkManager-wait-online
sudo systemctl disable NetworkManager-wait-online
  1. 禁用标准的wpa_supplicant
sudo systemctl stop wpa_supplicant
sudo systemctl disable wpa_supplicant
  1. 为无限网卡wlan0配置wpa_supplicant
sudo su
cd /etc/wpa_supplicant/
# 复制一份默认配置
cp wpa_supplicant.conf wpa_supplicant-wlan0.conf
# 生成要连接的无线配置
wpa_passphrase ssid password >>wpa_supplicant-wlan0.conf

wpa_supplicant-wlan0.conf内容如下:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN
network={
        ssid="ssid"
        #psk="password"
        psk=44116ea881531996d8a23af58b376d70f196057429c258f529577a26e727ec1b
}
  1. 安装对应的wpa_supplicant@wlan0服务
systemctl enable wpa_supplicant@wlan0

其中@后面的wlan0与前面配置文件名中的wlan0对应

  1. 修改/etc/network/interfaces,设置wlan0使用的IP和网关
auto wlan0
iface wlan0 inet static
address 10.127.227.10
netmask 255.255.255.0

auto wlan0:1
iface wlan0:1 inet static
address 192.168.0.210
netmask 255.255.255.0
gateway 192.168.0.1

这里我设置了两个IP,一个用于内部访问用,一个用来上公网,上公网的IP相应的设置了网关地址

  1. 配置DNS
# 禁用systemd-resolved,使/etc/resolv.conf配置的DNS生效
systemctl stop systemd-resolved
systemctl disable systemd-resolved
# 原来resolv.conf指向NetworkManager的配置,这里备份一下
cd /etc
mv resolv.conf resolv.conf.bak
# 生成新的resolv.conf
echo "nameserver 192.168.0.1" > resolv.conf
  1. 重启系统生效

你可能感兴趣的:(网络配置,ubuntu)