Network Commands Memo¶
rsync¶
Use the --dry-run option for testing and environment
RSYNC_PARTIAL_DIR=.rsync-tmp to keep partial files separates.
| diff -r /path/to/dir1/ /path/to/dir2/ | diff recursively two directories. |
| diff -rq /path/to/dir1/ /path/to/dir2/| sort | list files that differs between two directories |
| diff -rq /path/to/dir1/ /path/to/dir2/| diffstat | summarize differences between two directories |
| rsync -avn source-dir/ target-dir/ | what files differs (size mod time) between two directories. |
| rsync -avnc source-dir/ target-dir/ | what files differs (checksum) between two directories. |
| rsync -P rsync://rsync.server.com/path/to/file file | Use partial transfer, repeat for troublesome downloads. |
| rsync --bwlimit=1000 fromfile tofile | Locally copy with rate limit. It’s like nice for I/O |
| rsync -az --delete ~/public_html/ remote.com:’~/public_html’ | Mirror web site (using compression and encryption) |
| rsync -auz remote:/dir/ . && rsync -auz . remote:/dir/ | Synchronize current directory with remote one. |
ssh¶
More info in the ssh section.
| ssh $USER@$HOST command | Run command on $HOST as $USER (default command=shell) |
| ssh -f -Y $USER@$HOSTNAME xterm | Run GUI command on $HOSTNAME as $USER |
| ssh -c ‘chacha20-poly1305@openssh.com’ -f -Y $USER@$LANHOST xterm | Run GUI command on $LANHOST as $USER with faster crypto. |
| tar -cf- src | ssh -q -c arcfour128 $LANHOST tar -xf- -Cdest | quick directory transfer. |
| scp -p -r -C $USER@$HOST: file dir/ | Copy with permissions to $USER’s home directory on $HOST, compress for slow links. |
| scp -c arcfour128 $USER@$LANHOST: bigfile | Use faster crypto for local LAN, but tar over ssh is to be preferred. |
| ssh -g -L 8080:localhost:80 root@$HOST | Forward connections to $HOSTNAME:8080 out to $HOST:80 |
| ssh -R 1434:imap:143 root@$HOST | Forward connections from $HOST:1434 in to imap:143 |
| ssh -D 9999 $USER@$HOST | create a SOCKS proxy on localhost and port 9999 |
| ssh-copy-id $USER@$HOST | Install public key for $USER@$HOST for password-less log in |
wget¶
| (cd dir/ && wget -nd -pHEKk http://rest-sphinx-memo.readthedocs.org/) | Store local browsable version of a page to the current dir |
| wget -c http://www.example.com/large.file | Continue downloading a partially downloaded file |
| wget -r -nd -np -l1 -A ‘*.jpg’ http://www.example.com/dir/ | Download a set of files to the current directory |
| wget ftp://remote/file[1-9].iso/ | FTP supports globbing directly |
| wget -q -O- http://www.example.com/page | cat to /dev/stdout |
| echo ‘wget url’ | at 01:00 | Download url at 1AM to current dir |
| wget --limit-rate=20k url | Do a low priority download (limit to 20KB/s) |
| wget -nv --spider --force-html -i bookmarks.html | Check links in a file |
| wget --mirror http://www.example.com/ | Efficiently update a local copy of a site (handy from cron) |
networking¶
| ethtool eth0 | Show status of ethernet interface eth0 |
| ethtool --change eth0 autoneg off speed 100 duplex full | Manually set ethernet interface speed |
| iwconfig eth1 | Show status of wireless interface eth1 |
| iwconfig eth1 rate 1Mb/s fixed | Manually set wireless interface speed |
| iwlist scan | List wireless networks in range |
| ip link show | List network interfaces |
| ip link set dev eth0 name wan | Rename interface eth0 to wan |
| ip link set dev eth0 address 00:80:c8:f8:be:ef | Change mac address. |
| ip link set dev eth0 up | Bring interface eth0 up (or down) |
| ip addr show | List addresses for interfaces |
| ip addr add 1.2.3.4/24 dev eth0 | Add (or del) ip and mask (255.255.255.0) |
| ip route show | List routing table |
| ip route add default via 1.2.3.254 | Set default gateway to 1.2.3.254 |
| ip route add 192.168.16.0/28 via 192.168.31.254 | route subnet |
| ifconfig -a | List network interfaces |
| ifconfig eth0 1.2.3.4 up | Bring interface eth0 up (or down) |
| ifconfig eth0 1.2.3.4 netmask 255.255.255.0 | Add first ip and mask |
| ifconfig eth0:0 1.2.3.5 netmask 255.255.255.0 | Add additional ip and mask |
| route -n | List routing table |
| route add default gw 1.2.3.254 | Set default gateway to 1.2.3.254 |
| route add -net 192.168.16.0 netmask 255.255.240.0 gw 192.168.31.254 | route subnet |
| host github.com | Lookup DNS ip address for name or vice versa |
| hostname -i | Lookup local ip address (equivalent to host `hostname`) |
| whois mzlinux.org | Lookup whois info for hostname or ip address |
| sudo netstat -tupl | List internet services on a system |
| sudo netstat -tup | List active connections to/from system |
| sudo ss -tup | List tcp and udp active connections to/from system |
| iptraf | interactive ncurses colorful IP LAN monitor. |
| vnstat | Console hourly, daily and monthly network traffic. |
| lsof -i tcp:443 | What tcp connection is using port 443. |
| lsof -i :5800 | What is using port 5800. |
| lsof -i @192.168.1.5:22 | connections to host 192.168.1.5 port 22 |
| curl -I htps://github.org | Display the server headers for a web site. |
| curl -s https://ftp-master.debian.org/keys/archive-key-7.0.asc | gpg --import | Import a gpg key from the web |
| curl ifconfig.me | get your external address through ifconfig.me |
| sudo apache2ctl -S | Display a list of apache virtual hosts |
network manager¶
| nmcli | state of network-manager including Wireless Access Points |
| nmcli dev status | status of all devices |
| nmcli dev show | details of all devices and connections |
| nmcli dev show eth0 | details of a specific device. |
| nmcli radio wifi off | disable wifi |
| nmcli con show | list of registered connections |
| nmcli con show –active | list of active connections |
| nmcli con show df67bf87-452f-4a03-af4e-60f31afd749a | show connection details by uuid |
| nmcli con show id myaccess_pt | show connection details by id |
| nmcli con -f IP4.dns con show eth0-dhcp | dns of a connection |
| nmcli –show-secret –field 802-11-wireless-security.psk con show id myaccess_pt | show a connection password |
| nmcli connection del id ‘my access pt’ | delete connection |
| nmcli con modify id old_id connection.id new_id | change connection id |
| nmcli con up id MyWifi password mypasswd | connect with password |
| nmcli con edit conid | interactive edit the connection |
| nmcli dev wifi list | List available Wi-Fi access points. |
| nmcli -p dev wifi list | pretty list of all availables wifi access points |
| nmcli dev wifi connect FreeWifi | setup and activate a new connection |
| nmcli dev wifi connect apssid name conname password private | new connection with name and password |
| nmcli -f IP4 dev show eth0 | IPV4 adress, gateway, and dns |
| nmcli -f general.connection dev show eth0 | active connection on an iface |
| nmcli dev disconnect wlan0 | disconnect wlan0 interface |
| curl -F login=myid -F password=mypasswd https://wifi.provider.org/Auth | Connect to open spot |