HOWTO: Quick ‘n’ dirty networking commands

224

After my quick blog around command line networking and ethernet setup, I’ve decided to report here few useful command I use most. When you setup your own ethernet card on the fly you even need to use them quite often.

As usual these commands are easy and heavily used when you deal with command line setup, this is just a reminder for me and you, some sort of place where I can put “my most used commands”, please feel free to add your own to the post as well

Here’s something related to basic hostname handling (really really easy):

# Hostname lookup through DNS query
host www.linux.com

# lookup current host name and/or ip address
hostname

# WHOIS query for a domain
whois linux.com

Here’s something related to netstat and ip tools (a little more interesting)

# Get a list of internet service on your current system
netstat -tup
netstat -tupl

# now some stats from your ethernet device (ethtool package needed)
boba:~# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: pg
Wake-on: g
Current message level: 0x00000037 (55)
Link detected: yes

# Now let's change ethernet interface speed manually (sounds nice...)
ethtool --change eth0 autoneg off speed 100 duplex full

# Now some fun with IP command utility
#-----------------------------------------------------------------------

# networking stats with IP (ip addr show)
boba:~# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:46:ce:0e:59 brd ff:ff:ff:ff:ff:ff
boba:~# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:46:ce:0e:59 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.8/24 brd 10.0.0.255 scope global eth0

# Set network interface up (or down)
ip link set dev eth0 up

# Rename network interface (from eth0 to wifi0 or the name you want)
ip link set dev eth0 name wifi0

# some basic ip settings, already seen something on previous blog
# add ip and mask (255.255.255.0)
ip addr add 1.2.3.4/24 brd + dev eth0
# list routing table
ip route show
# add default gateway
ip route add default via 1.2.3.1

Let’s add delay or latencies to devices (tricky), in this case 10ms latency to eth0

boba:~# tc qdisc add dev eth0 root handle 1:0 netem delay 10msec

# Ok, let's remove it
tc qdisc del eth0 root

And finally something related to wireless cards

# Scan wireless networks in range
iwlist scan

# Status advanced status of first wireless ethernet card
iwconfig eth1

# Manually set wireless card speed
iwconfig eth1 rate 2Mb/s fixed

I’ll add my own commands to the article when something comes in my mind, you’re free to add your own here if you want. See also my previous Howto: Setup ethernet from command line

Glad to see your comments

 

Andrea (Ben) Benini