Blog Post

...

CentOS 7: usb wifi (8188eu) setup

There are many complaining posts online telling about almost impossible wifi adapter installation within CentOS. After a quick look at the forums dedicated to this problem I’ve got an impression that nowadays very few adapters could be installed in CentOS and people ask which exact usb wifi will work by them for sure. In this article I’ll provide a complete approach how to install a usb wifi for your server (CentOS 7 minimal, command line only).

Given a device to install TP-Link (TL-WN725N). First of all we need to find a proper driver for it. CentOS 7 (linux kernel 3.10) shipped with wireless driver pack (/lib/modules/`uname -r`/kernel/drivers/net/wireless), sad, but most of Realtek drivers won’t work. For current device a driver was not shipped, so I had to compile it manually. To check if device connected to usb 2.0 and to get its specifications, run lsusb command:

[root@localhost ~]# lsusb
Bus 001 Device 002: ID 0bda:8179 Realtek Semiconductor Corp. RTL8188EUS 802.11n Wireless Network Adapter

 

From this output we extract vendorId 0bda and deviceId 8179, plus there is a supposed chipset number rtl8188eu. To get the code for this chipset I used a not official, community source. Please follow instructions under this link to compile and install current driver (there are 2 options, I’ve used dkms, for this dkms package should be installed). If you also choose dkms kernel module installation, a *.ko binary at /var/lib/dkms and a config-file at /usr/src/*8188eu*/dkms.conf will be generated:

PACKAGE_NAME="8188eu"
PACKAGE_VERSION="1.0"
BUILT_MODULE_NAME="8188eu"
DEST_MODULE_LOCATION="/kernel/drivers/net/wireless/"
...

 

Here we take build_module_name and check if driver module successfully injected using lsmod command:

[root@localhost ~]# lsmod | grep 8188eu
8188eu                768700  0

 

If lsmod command gives such a result, then the module is loaded, we can go further. Now we should manage our connection. I guess the most used tool for this is the NetworkManager (nmcli or nmtui its command line implementations). Unfortunately nmcli package is still raw (at this moment) for CentOS 7: it finds that some device is connected to an USB interface (<interface>), but can not figure out this device, it is marked as unmanaged.

To connect to wireless network I used wpa_supplicant tool - my router uses WPA protocol. Let’s run ip addr command to find the USB interface to which wifi device connected:

[root@localhost ~]# ip addr
3: wlp0s20u2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state DOWN qlen 1000 
    link/ether ma:ca:dd:rx:xx:xx brd ff:ff:ff:ff:ff:ff

 

So <interface> = wlp0s20u2 for my PC. Now let’s use wpa_supplicant to connect to network and dhclient to request the router to assign to our PC some local IP address:  

wpa_supplicant -i wlp0s20u1 -c /etc/wpa_supplicant/wpa_supplicant.conf -B

dhclient wlp0s20u1

 

File wpa_supplicant.conf should already persist at the disk, you need to add to it the following lines that include your network SSID and a PSK (password):

network={
    ssid="<put-your-ssid-here>"
    psk="<put-your-psk-here>"
    priority=1
}

 

Now we can try to ping some local address and some external address (ping 8.8.8.8). If local network accessible, but external not, we need to check the gateway address. Run the command netstat –nr, if gateway address differs from your router’s gateway address, then we use this command (where 192.168.2.1 – gateway ip):

[root@localhost ~]# /sbin/route add -net 0.0.0.0 gw 192.168.2.1 wlp0s20u1

[root@localhost ~]# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.2.1     0.0.0.0         UG        0 0          0 wlp0s20u2
192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 wlp0s20u2

 

Great, internet should be accessible now. But after reboot we have to again run wpa_supplicant and and dhclient. To make these tasks auto bootable we should provide two services (daemons). Since 7 version CentOS started to use systemd as a new primary tool (replacement of init.d sysV) for daemon management, we can use it to bootup our tasks. Fortunately wpa_supplicant package in CentOS 7 provides already systemd service for it (/usr/lib/systemd/system/wpa_supplicant.service). It uses EnvironmentFile (/etc/sysconfig/wpa_supplicant) which should point to our usb interface:

# Use the flag "-i" before each of your interfaces, like so:
#  INTERFACES="-ieth1 -iwlan0"
INTERFACES="-iwlp0s20u2"

# Use the flag "-D" before each driver, like so:
#  DRIVERS="-Dwext"
DRIVERS=""

# Other arguments
OTHER_ARGS="-u -f /var/log/wpa_supplicant.log -P /var/run/wpa_supplicant.pid"

 

To enable this service boot at startup, run this command: systemctl enable wpa_supplicant.service.

At the moment of the writing of this article, dhclient as a systemd service within CentOS does not exist. So let’s create a /etc/systemd/system/mdhclient.service:

[Unit]
Description=dhclient service
Before=network.target
After=syslog.target
Requires=wpa_supplicant.service 

[Service]
Type=forking
PIDFile=/var/run/dhclient.pid
ExecStart=/sbin/dhclient wlp0s20u2

[Install]
WantedBy=multi-user.target

 

To enable mdhclient service boot at startup, use this command: systemctl enable mdhclient.service.

That’s it. Even after system restart your wifi adapter will work perfect without any additional actions.

Comments (14)

Tags: centos


Comments:

...

vinisha Sep 22, 2015 at 01:07 #

Great article! I followed all the steps mentioned here. But I don't see any network config files for wireless adapter in /etc/sysconfig/network-scripts/ifcfg-*. I was wondering whether I missed any steps?

...

Stanislav Sep 26, 2015 at 12:04 #

Hi Vinisha, thank you for your your comment. To connect to WIFI I did not use these ifcfg-* files. Instead I used wpa_supplicant tool, please have a look at it.

...

Cyrus Dec 27, 2015 at 16:36 #

I followed your steps in the article and all seems to work fine when the connection is uninterrupted. How to auto reconnect to the WiFi router upon disconnection without crond and ping test :) ?

...

Stanislav Dec 30, 2015 at 16:47 #

Cyrus, I'm not sure, but you can try to set the following for systemctl: [Service] Restart=always RestartSec=30

...

0xcb0 Blog Mar 09, 2016 at 20:04 #

[Trackback] There is a Banana Pi 1st generation, that was sitting in my drawer for too long. So I decided to bring it back to life with CentOS to which I&#8217;m a newbie. My first target is to use a TL-WN725N Nano-USB Wlan Device to connect to my local network. T...

...

Stanislav Mar 16, 2016 at 09:17 #

Hey Marcus, thank you for a great feedback to this post!

...

Ajay Apr 03, 2016 at 21:10 #

When I try to connect to isp router with gateway 192.168.1.254, I am unable to get a DHCPACK. I am able to login to wifi using "wpa_supplicant", but "dhclient", continues forever with DHCPDISCOVER, DHCPREQUEST and DHCPOFFER messages. These message are being broadcasted at right dhcp port. DHCPACK and ip binding never happens. I have provided the route plan to reach gateway 192.168.1.254. I am able to connect to mobile tethering wifi. Any advice to get DHCPACK ?? Thanks !!

...

Stanislav Apr 04, 2016 at 11:02 #

Ajay, dhcclient should work. Make sure that interface id is the same as the command "ip addr" gives back.

...

Ajay Apr 05, 2016 at 02:13 #

Thanks Stanislav, I am right now using Centos 7.2. Do you think using Centos 7.0 will help ? I have tried everything, so this is only thing to try changing Centos to 7.0. As I said , it connects fine to mobile phone tethering wifi. So I am providing all the proper interface id's. But it, just is unable to get ip from ISP router. Just FYI, on latest update to Centos 7.2 , nmcli now recognizes the device as Wifi.

...

Stanislav Apr 06, 2016 at 09:21 #

Ajay, I'm not sure that using Centos 7.2 will help. Is there a chance to try another router? Thanks for your information about nmcli in Centos 7.2, I appreciate it.

...

Greg Jun 10, 2016 at 14:37 #

Hi, great article. I'm using CentOS 7 (linux kernel 3.10) and the device get detected as enp0s20u2 (Ethernet). Do you know can I fix this? Thank you!

...

indra Aug 15, 2016 at 09:44 #

Hi Greg, (unless you have already sorted out the solution) I have experienced the same problem (kernel 3.10) while using the driver that came from the CD of the network card provider. Later I use the driver by Larry Finger (the link provided above by Stanislav as "source") and this works. Note the default NetworkManager () of CentOS crashed but the wifi is working (blinking light) but this is sort of problem of NetworkManager of CentOS [follow https://github.com/lwfinger/rtl8188eu/issues/162 ]. The crash of NetworkManager can stop the functionality of ethernet. One can get back the NetworkManager and ethernet but that is another set of long process.

...

Gilbert Standen Oct 02, 2016 at 20:34 #

Thank you so much for this blog post Stanislav! The procedures on this blog post also worked for Oracle Linux UEK3 kernel Linux ol72.orabuntu-lxc.com 3.8.13-118.11.2.el7uek.x86_64 #2 SMP Following the comment by Greg & Indra I used the driver from the github here: https://github.com/lwfinger/rtl8188eu/issues/162 and this did successfully get the interface recognized as a wireless interface. Because of the onboot conflicts I mentioned earlier, I opted to just create a script /root/usb-wireless-up-uek3.sh and then add a line to the sudoers file: myusername ALL = (root) NOPASSWD: /root/usb-wireless-up-uek3.sh cat /home/username/Desktop/usb-wireless-up-uek3.sh sudo /root/usb-wireless-up-uek3.sh cat /root/usb-wireless-up-uek3.sh wpa_supplicant -i wlp0s20f0u2 -c /etc/wpa_supplicant/wpa_supplicant.conf -B sleep 10 ifup wlp0s20f0u2

...

Harvey Jul 08, 2017 at 18:39 #

Thanks for the writeup! Spent some time trying to get the tplink device to work with iw but 'iw dev' kept showing "nl80211 not found" and NetworkManager-wifi didn't let me add a wifi setting. Using wpa_supplicant in the steps above did the trick. BTW, instead of installing the driver from source, it can also be installed by 'sudo yum install kmod-8188eu' through the epel repo. And for some reason, my device showed as enp0s26f7u1. It didn't seem to play nice on other usb ports at u2, u3, or u4. Just adding some notes for others trying to get this TP-LINK TL-WN725N device to work reliably under Centos 7.3.

Leave a Comment