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

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

配置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. 重啓系統生效
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章