Posts tagged iproute2

linux wifi cli handling

posted on 2016-06-04 14:56

Here's a walktrough on using a linux computer with a wifi card to access wlans via the cli tools. This guide is debian specific and assumes you use one of the WPA protocols for encrypting your wifi.

available tools

  • ip
  • iw
  • iwlist
  • iwconfig
  • dhclient
  • wpa_supplicant
  • wpa_passphrase
  • /etc/network/interfaces
  • wicd

You can use all of these, but it just happens you do not really need them all.

discern wlan IF

iw dev:

    Interface wlan0
    ifindex 2
    wdev 0x1
    addr 00:22:66:88:00:22
    type managed

wlan0 is my wifi interface and will be uses as an example here from now on.

enable IF (if needed)

ip l s dev wlan0 up

find networks

iw dev wlan0 scan | grep -i -e ssid -e signal


    signal: -79.00 dBm
SSID: ng-2.4G
signal: -85.00 dBm
SSID: ng-5G

So you know the available networks as well as the signal quality.

An alternative would be: iwlist wlan0 scan | grep -i -e ssid -e signal:

    Quality=26/70  Signal level=-84 dBm  
    Quality=36/70  Signal level=-74 dBm  

I will choose ng-2.4g for the next examples.

set up WPA and run daemon

# i just do not like these storing under /etc
mkdir /root/.wpa
# you are promted for the passphrase
# tee is used to show the output written to the file also directly at the shell
wpa_passphrase ng-2.4g | tee -a ~/.wpa/wpa_supplicant.conf  
## hide contents from others since the original pass is included as comment
chmod 600 ~/.wpa/wpa_supplicant.conf
# run daemon in the backgroud, automtically brings IF up
wpa_supplicant -B -i wlan0 -c ~/.wpa/wpa_supplicant.conf

So now your wpa_supplicant.conf should contain something like this:

root@zen:/home/sjas/blog# wpa_passphrase ng-2.4G MY_PASSWORD

This is likely not everything you need to connect. So either discern everything else that is missing parameter-wise by hand, or use wicd if you have a desktop environment installed.

Once you connected to the wifi of your choice, do ps aux | grep wpa_supplicant and see how it was started, and which config references via -c. Copy its contents over to your wpa_supplicant.conf.

set up interface in /etc/network/interfaces for automatic connecting

manual wlan0
iface wlan0 inet dhcp
    pre-up wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
    post-down killall -q wpa_supplicant


# enable
ifup wlan0

ifdown wlan0

how about several wlan configurations?

This is what I might use in my case:


manual wlan0
iface home2 inet dhcp
    pre-up wpa_supplicant -B -D wext -i wlan0 -c /var/lib/wicd/configurations/c404150241b4
    post-down killall -q wpa_supplicant
iface home5 inet dhcp
    pre-up wpa_supplicant -B -D wext -i wlan0 -c /var/lib/wicd/configurations/c404150241b3
    post-down killall -q wpa_supplicant

These have to be used a little differently, i.e.:

## acitivate one network:
ifup wlan0=home2
## and deactivate
ifdown wlan0

## or activate the other one:
ifup wlan0=home5
## and deactivate
ifdown wlan0

This may seem quite a bit unwieldy, but I am just fed up with network-manager or its relative, wicd, by now.

ip commands in linux

posted on 2014-06-23 17:28:11

The currently usually used tools and which ones will succeed these:

Purpose                        | Legacy net-tools | iproute2
Address and link configuration | ifconfig         | ip addr, ip link
Routing tables                 | route            | ip route
Neighbors                      | arp              | ip neigh
VLAN                           | vconfig          | ip link
Tunnels                        | iptunnel         | ip tunnel
Multicast                      | ipmaddr          | ip maddr
Statistics                     | netstat          | ss

This blog covers .csv, .htaccess, .pfx, .vmx, /etc/crypttab, /etc/network/interfaces, /etc/sudoers, /proc, 10.04, 14.04, 16.04, AS, ASA, ControlPanel, DS1054Z, GPT, HWR, Hyper-V, IPSEC, KVM, LSI, LVM, LXC, MBR, MTU, MegaCli, PHP, PKI, PS1, R, RAID, S.M.A.R.T., SNMP, SSD, SSL, TLS, TRIM, VEEAM, VMware, VServer, VirtualBox, Virtuozzo, XenServer, acpi, adaptec, algorithm, ansible, apache, apache2.4, apachebench, apple, applet, arcconf, arch, architecture, areca, arping, asa, asdm, autoconf, awk, backup, bandit, bar, bash, benchmarking, binding, bitrate, blackarmor, blockdev, blowfish, bochs, bond, bonding, booknotes, bootable, bsd, btrfs, buffer, c-states, cache, caching, ccl, centos, certificate, certtool, cgdisk, cheatsheet, chrome, chroot, cisco, clamav, cli, clp, clush, cluster, cmd, coleslaw, colorscheme, common lisp, configuration management, console, container, containers, controller, cron, cryptsetup, csync2, cu, cups, cygwin, d-states, database, date, db2, dcfldd, dcim, dd, debian, debug, debugger, debugging, decimal, desktop, df, dhclient, dhcp, diff, dig, display manager, dm-crypt, dmesg, dmidecode, dns, docker, dos, drivers, dtrace, dtrace4linux, du, dynamictracing, e2fsck, eBPF, ebook, efi, egrep, emacs, encoding, env, error, ess, esx, esxcli, esxi, ethtool, evil, expect, exportfs, factory reset, factory_reset, factoryreset, fail2ban, fakeroot, fbsd, fdisk, fedora, file, files, filesystem, find, fio, firewall, firmware, fish, flashrom, forensics, free, freebsd, freedos, fritzbox, fsck, fstrim, ftp, ftps, g-states, gentoo, ghostscript, git, git-filter-branch, gitbucket, github, gitolite, global, gnutls, gradle, grep, grml, grub, grub2, guacamole, hardware, haskell, hdd, hdparm, hellowor, hex, hexdump, history, howto, htop, htpasswd, http, httpd, https, i3, icmp, ifenslave, iftop, iis, imagemagick, imap, imaps, init, innoDB, innodb, inodes, intel, ioncube, ios, iostat, ip, iperf, iphone, ipmi, ipmitool, iproute2, ipsec, iptables, ipv6, irc, irssi, iw, iwconfig, iwlist, iwlwifi, jailbreak, jails, java, javascript, javaws, js, juniper, junit, kali, kde, kemp, kernel, keyremap, kill, kpartx, krypton, lacp, lamp, languages, ldap, ldapsearch, less, leviathan, liero, lightning, links, linux, linuxin3months, lisp, list, livedisk, lmctfy, loadbalancing, locale, log, logrotate, looback, loopback, losetup, lsblk, lsi, lsof, lsusb, lsyncd, luks, lvextend, lvm, lvm2, lvreduce, lxc, lxde, macbook, macro, magento, mailclient, mailing, mailq, make-jpkg, manpages, markdown, mbr, mdadm, megacli, micro sd, microsoft, minicom, mkfs, mktemp, mod_pagespeed, mod_proxy, modbus, modprobe, mount, mouse, movement, mpstat, multitasking, myISAM, mysql, mysql 5.7, mysql workbench, mysqlcheck, mysqldump, nagios, nas, nat, nc, netfilter, networking, nfs, nginx, nmap, nocaps, nodejs, numberingsystem, numbers, od, onyx, opcode-cache, openVZ, openlierox, openssl, openvpn, openvswitch, openwrt, oracle linux, org-mode, os, oscilloscope, overview, parallel, parameter expansion, parted, partitioning, passwd, patch, pct, pdf, performance, pfsense, php, php7, phpmyadmin, pi, pidgin, pidstat, pins, pkill, plasma, plesk, plugin, posix, postfix, postfixadmin, postgres, postgresql, poudriere, powershell, preview, profiling, prompt, proxmox, ps, puppet, pv, pveam, pvecm, pvesm, pvresize, python, python3, qemu, qemu-img, qm, qmrestore, quicklisp, quickshare, r, racktables, raid, raspberry pi, raspberrypi, raspbian, rbpi, rdp, redhat, redirect, registry, requirements, resize2fs, rewrite, rewrites, rhel, rigol, roccat, routing, rs0485, rs232, rsync, s-states, s_client, samba, sar, sata, sbcl, scite, scp, screen, scripting, seafile, seagate, security, sed, serial, serial port, setup, sftp, sg300, shell, shopware, shortcuts, showmount, signals, slattach, slip, slow-query-log, smbclient, snmpget, snmpwalk, software RAID, software raid, softwareraid, sophos, spacemacs, spam, specification, speedport, spi, sqlite, squid, ssd, ssh, ssh-add, sshd, ssl, stats, storage, strace, stronswan, su, submodules, subzone, sudo, sudoers, sup, swaks, swap, switch, switching, synaptics, synergy, sysfs, systemd, systemtap, tar, tcpdump, tcsh, tee, telnet, terminal, terminator, testdisk, testing, throughput, tmux, todo, tomcat, top, tput, trafficshaping, ttl, tuning, tunnel, tunneling, typo3, uboot, ubuntu, ubuntu 16.04, ubuntu16.04, udev, uefi, ulimit, uname, unetbootin, unit testing, upstart, uptime, usb, usbstick, utf8, utm, utm 220, ux305, vcs, vgchange, vim, vimdiff, virtualbox, virtualization, visual studio code, vlan, vmstat, vmware, vnc, vncviewer, voltage, vpn, vsphere, vzdump, w, w701, wakeonlan, wargames, web, webdav, weechat, wget, whois, wicd, wifi, windowmanager, windows, wine, wireshark, wpa, wpa_passphrase, wpa_supplicant, x11vnc, x2x, xfce, xfreerdp, xmodem, xterm, xxd, yum, zones, zsh

Unless otherwise credited all material Creative Commons License by sjas