Published on

linux设置wifi

Authors
  • avatar
    Name
    yushenw
    Linkedin

连接

查看无线设备

iwconfig

使用netplan连接wifi

sudo apt update
# 安装必要软件
sudo apt install wpasupplicant net-tools
sudo vi /etc/netplan/01-netcfg.yaml
# 配置
network:
  version: 2
  renderer: networkd
  wifis:
    wlan0:
      dhcp4: true
      optional: true
      access-points:
        "your-ssid-name":
          password: "your-wifi-password"
sudo netplan apply #将配置生效
# 连接wifi
sudo ifconfig wlan0 up
sudo iwconfig wlan0 essid "your-ssid-name"
sudo dhclient wlan0

加密

  1. 使用hash:
# 得到的psk即为密码
wpa_passphrase your-ssid-name your-wifi-password
  1. 使用环境变量
export YOUR_PASSWORD="your-wifi-password"
# 修改netplan配置
access-points:
        "test-ssid":
          password: $YOUR_PASSWORD
# 使配置生效
sudo netplan apply
  1. 使用 network-manager 连接wifi
sudo apt install -y network-manager
sudo nmcli device wifi connect test-ssid password your-wifi-password

重启wlan0

sudo netplan apply

# 禁用wlan0设备
sudo ip link set wlan0 down
# 启用
sudo ip link set wlan0 up

查看

ifconfig 
# or
ipaddress

# 只显示 wlan0设备
ip addr show dev wlan0