centos命令行连WIFI

linux系统没有安装X windows界面时只是命令行,而无法显示WIFI

在这种情况下怎么连接wifi呢?

centos命令行连WIFI_第1张图片

  • 查看状态
# 安装配置工具,安装net-tools后,可以使用ifconfig
yum install iw
yum install wpa_supplicant
yum install net-tools

# 查看无线网接口
iw dev
# interface wlp3s0  ... addr ... type...
# 有channel 1 (2412 MHz)....表示已连接

# 查看接口连接信息
iw wlp3s0 link
# Not connectted.   未连接
# Connected to ...  SSID:test... 已连接

# 查看网络接口/网卡状态
ifconfig
# 注:未连接wifi前,/etc/sysconfig/network-scripts没有发现wlp3s0的配置,
# 连接成功之后,出现同wifi的SSID相同名称的配置


# 查看网络接口/网卡状态
ip addr     # 会显示已获取的IP
ip link     # 显示网卡

# 启用/禁用wlp3s0接口,两种方法等同。up时需要数秒
ifconfig wlp3s0 up/down     # ping提示:connect: Network is unreachable
ip link set dev wlp3s0 up/down  # ping提示:Name or service not known
  •  
  • 连接配置
# 启用wlp3s0接口
ip link set dev wlp3s0 up

# 查看周围wifi
iw dev wlp3s0 scan | grep SSID

# 连接wifi,指定SSID(wifi名称)和password(wifi密码)
wpa_supplicant -B -i wlp3s0 -c <(wpa_passphrase "ssid" "password")
# Successfully initialized wpa_supplicant

# 或者
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
# 内容如下:
+++++++++++++++++++++++++++++++++++++
ctrl_interface=/var/run/wpa_supplicant
#ctrl_interface_group=wheel
ap_scan=1
network={
        ssid="ssid名称"
        scan_ssid=1
        key_mgmt=WPA-PSK
        psk="实际密码"
}
++++++++++++++++++++++++++++++++++++

# 用dhcp获得IP
dhclient wlp3s0

# 查看ip
ip addr show wlp3s0
#  UP表示接口已启用
# wlp3s0 inet 192.168.*.* brd .... int6 .....,无线网卡已获取ip,网络已连接
# 同时/etc/sysconfig/network-scripts出现ifcfg-"ssid"配置文件

 

 

你可能感兴趣的:(linux)