首页 > 代码库 > ubuntu server 16.04命令行设置wifi

ubuntu server 16.04命令行设置wifi

想装个Server版的Linux系统玩玩,下面记录一下ubuntu server 16.04怎么设置WiFi的问题:

首先查看自己网卡的信息:一般人的都是eth0,和wlan0,但在Ubuntu Server 16.04里面变成了enp4s0和wlp5s0,算是第一个坑吧,

ubuntu@ubuntu:~$ ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: enp4s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 28:d2:44:98:33:2a brd ff:ff:ff:ff:ff:ff
3: wlp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 18:cf:5e:00:84:ba brd ff:ff:ff:ff:ff:ff inet 192.168.224.102/24 brd 192.168.224.255 scope global wlp5s0 valid_lft forever preferred_lft forever inet6 fe80::1acf:5eff:fe00:84ba/64 scope link valid_lft forever preferred_lft forever


ubuntu-server16.0本身没有自带wpa_supplicant,所以一开始必须连接有线网络安装

apt-get install wpasupplicant

把WiFi-ssid和密码写入一个配置文件

wpa_passphrase ssid password > xxx.conf

编辑网络配置文件vi /etc/network/interfaces

source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback

#下面是添加的内容
auto wlp5s0 iface wlp5s0 inet dhcp wpa-conf /home/ubuntu/xxx.conf  #wap-conf -符号前面没有空格

接下来有两种方法获取ip地址(如果不行可以先reboot一下):

1、自动获取ip地址:

dhclient wlp5s0

2、手动获取ip地址: 

  • -B - fork into background
  • -c filename - path to configuration file
  • -i interface - interface to listen on
wpa_supplicant  -i wlp5s0  -c /home/ubuntu/xxx.conf


原文链接:http://www.linuxidc.com/Linux/2016-05/131486.htm

ubuntu server 16.04命令行设置wifi