Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged Network from sorted by
Terminal - Commands tagged Network - 120 results
telnet 0 <port>
2012-11-16 03:38:49
User: somaddict
Functions: telnet
0

Super fast way to ftp/telnet/netcat/ssh/ping your loopback address for testing. The default route 0.0.0.0 is simply reduced to 0.

sudo tc qdisc add dev lo root netem delay 500ms
2012-11-05 05:29:51
User: caiosba
Functions: sudo
Tags: Network delay tc
7

Replace 500ms by the desired delay.

To remove it: sudo tc qdisc del dev lo root netem delay 500ms

echo foo | ncat [ip address] [port]
2012-10-26 10:53:47
User: dragonauta
Functions: echo
-1

you can use a pair of commands to test firewalls.

1st launch this command at destination machine

ncat -l [-u] [port] | cat

then use this command at source machine to test remote port

echo foo | ncat [-u] [ip address] [port]

First command will listen at specified port.

It will listen TCP. If you use -u option will listen UDP.

Second command will send "foo" through ncat and will reach defined IP and port.

for i in `ls /sys/class/net/`; do echo $i: `cat /sys/class/net/$i/operstate`; done
2012-10-15 18:20:37
User: dragonauta
Functions: echo
Tags: Network device
0

no need for installing mii-tools, all generic tools

working under archlinux.

curl -s mi-ip.net | grep '"ip"' | cut -f2 -d ">" | egrep -o '[0-9.]+'
2012-10-15 16:48:20
User: dragonauta
Functions: cut egrep grep
0

looks at html for "ip" (it's a CSS class), then a little of cut and egrep to get IPv4 address.

I use this oneliner into conky.

sudo /etc/init.d/dns-clean
2012-08-06 18:40:49
User: varghjarta
Functions: sudo
Tags: Network Ubuntu
0

Flush the DNS cache under Ubuntu (Debian?)

nmap -T4 -sn 192.168.1.0/24
2012-06-19 17:07:24
User: drewbled
0

Does a ping scan on the local subnet and returns the IPs that are up

curl ifconfig.me/all
2012-05-16 18:22:28
User: pykler
9

Gets all kind of info, ifconfig.me rocks ...

for just the ip addess you can use ifconfig.me or ifconfig.me/ip

curl ip.nu
fping -r1 -Aag <network>/<cidr_mask> 2>/dev/null | sort -gt. -k4
2011-12-21 22:38:51
User: SuperJC
Functions: sort
Tags: Network
0

Prevents the need for the grep & awk statements. Sort is optional if you don't care about the output order. The network range can also be specified as in the original post.

-A Display targets by address rather than DNS name. (Probably unnecessary...)

-a Show systems that are alive.

S fping -r1 -ag 192.168.nnn.0/24 2>/dev/null

Without sorting...

netstat -anpe
2011-12-06 18:27:09
User: anarcat
Functions: netstat
1

Lists all opened sockets (not only listeners), no DNS resolution (so it's fast), the process id and the user holding the socket.

Previous samples were limiting to TCP too, this also lists UDP listeners.

wget ifconfig.me/ip -q -O -
fping -g 192.168.1.1 192.168.1.10 -r 1 | grep -v unreachable | awk '{print $1}'
until ping -c1 ADDRESS;do true;done;zenity --warning --text "ADDRESS is back"
2011-09-26 18:51:38
User: marcusrp
Functions: ping
Tags: Network zenity
5

I'd rather this one on Gnome, as I'm used to be listening some music while working. I've even created a bash function which receives ADDRESS as parameter.

route -n | perl -ne '$ANY="0.0.0.0"; /^$ANY/ and split /\s+/ and print "Gateway to the World: ",($_[1]!=$ANY)?$_[1]:(`ip address show $_[$#_]`=~/peer ([0-9\.]+)/ and $1),", via $_[$#_].\n"'
curl http://my-ip.cc/host.json
2011-09-01 00:31:49
User: samleb
0

JSON version.

Additionally it may give your geolocation if it's known by hostip.info

curl http://my-ip.cc/host.xml
2011-09-01 00:30:03
User: samleb
-1

XML version.

Additionally it may give your geolocation if it's known by hostip.info

curl http://my-ip.cc/host.txt
2011-09-01 00:28:49
User: samleb
-1

Additionally it may give your geolocation if it's known by hostip.info

watch -n 2 -d '/sbin/ifconfig eth0'
ip addr show eth0 | grep ether | awk '{print $2}'
2011-05-01 19:54:46
User: ryanc
Functions: awk grep
Tags: Network Linux
-2

Linux specific, requires iproute2 (but most distros have that by default now)

while cat /proc/net/dev; do sleep 1; done | awk '/eth0/ {o1=n1; o2=n2; n1=$2; n2=$10; printf "in: %9.2f\t\tout: %9.2f\r", (n1-o1)/1024, (n2-o2)/1024}'
while :; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
while [ /bin/true ]; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done
2011-03-22 10:02:23
User: hons
Functions: awk cut echo grep sleep tr
15

Just a simple way without the need of additional tools. Of course, replace eth0 with your IF.

iperf -s
2011-01-24 07:58:38
User: forcefsck
8

On the machine acting like a server, run:

iperf -s

On the machine acting like a client, run:

iperf -c ip.add.re.ss

where ip.add.re.ss is the ip or hostname of the server.

nc -l -p 7777 > /dev/null
2011-01-24 00:06:45
User: kerim
1

On the another machine write this command.

pv -r /dev/zero | nc 192.168.1.1 7777

It will show live throughput between two machine.The destination machine ip is at our example 192.168.1.1

You must multiply by 8 for the network calculation.

You must install pv and netcat commands for this commands usage.

kerim@bayner.com

http://www.bayner.com/