Networking & remote access

From English Wiki
Jump to navigation Jump to search

The following are common and useful commands and utilities in Linux for managing networking, networking related functions, and remote access.


1 General networking

Command Function
/etc/n­etw­ork­/in­ter­faces Location of network interface information
cd dir Access a directory called dir_name on a remote computer.
curl -O URL Download contents of a webpage
curl URL Get or display file from URL
curl ifconf­ig.me Find one’s external IP address
dig Query DNS servers for information on a domain
dig -x IP_address Check DNS for reverse lookup an active IP address
dig domain Find DNS information and configuration on an active domain name.
dig@I­P domain -t AXFR DNS Zone Transfer
echo "nameserver /etc/r­eso­lv.conf Add DNS Server
echo "­1" /proc/­sys­/ne­t/i­pv4/ip forward Enable IP Forwarding
ethtool eth0 Query or control network driver and hardware settings
export MAC=M­AC_address Change MAC Address
get file Download a file from a remote computer to the local machine
host -I hostname Display the local IP address of a specified hostname with other information.
host -l domain nameserver DNS Zone Transfer
host IP Domain Lookup IP
host domain Display DNS ip address for domain
hostname -i Display the network address of the host name.
hostname -I Display all local IP addresses
hostname -I Display IP address
hostna­mectl set-h­ostname hostname Manage hostname (/etc/h­ostname) without restarting
ifconfig Display the IP and MAC address of a system
ifconfig -a Display all network interfaces and IP addresses
ifconfig interface IP­/CI­DR Set IP and netmask
ifconfig interface mtu size Change MTU size
ifconfig eth0 Display eth0 address and details
ifconfig eth0 IP up Activate eth0 with specified IP address
ifconfig eth0 down Deactivate eth0
ifconfig eth0 up Activate eth0
ifconfig eth0:1 IP­/CI­DR Set virtual interface
ifconfig int hw ether MA­C_address Change MAC Address
ifdown interf­ace Down an interface
ifup interf­ace Up an interface
ip a Display all system IP addresses
ip addr add IP_address dev eth1 Add a temporary IP address to interface eth1
ip addr show Display network interfaces and their related IP addresses
ip address add IP_address Used under interface eth0 to assign an IP address.
ip r Show IP addresses for local host (same as 'route')
lsof -i Establ­ished Connec­tions
mail -s 'mail_subject' -c 'cc-mail_address' -b 'bcc-mail_address' 'to-mail_address' Send an email from the terminal
nc -vz host port Scan port in host
netstat -ant TCP connec­tions
netstat -anu UDP Connec­tions
netstat -nutlp Display listening tcp and udp ports and corresponding programs (a netstat command)
netstat -pnltu Display all listening ports (a netstat command)
netstat -r -v Prints network routing, information, and connections
netstat -tuln All tcp and udp listening ports
netstat -tulpn Connec­tions with PIDs
ping -c hostname Ping an IP address and stop after a specified number of replies
ping domain/IP Ping a host by domain name or IP (send ICMP echo request)
ping host-ip Check connectivity between two hosts
quit Logout from a remote connection.
route, route -n Display kernel IP routing table (local host IP addresses)
route add -net IP Tell other systems which network to route a system on
route add default gw IP Add a default gateway
route add default gw IP Set Default Gateway
share user IP c$ Mount Windows Share
smb://­IP­/­sharename Access Windows SMB Share
ss -tuln All tcp and udp listening ports
ssh -i Grants user access to openSSH client.
SSH user@ip_address OR host Enables SSH login or sign-in to a remote Linux machine by specifying the machine's username and IP address.
tcpdump Dump network traffic
telnet Grants access to the Telnet protocol user interface.
traceroute Show places where packets travel to reach an address
watch ss -tp Network Connec­tions
wget --rand­om-wait -r -p -e robots=off -U URL Download an entire website
wget -c file Continue an interrupted download
wget URL Download file from a URL, http://domain.com/file
whois domain Show whois information for a domain


2 Networking: Remote access

Command Function
/etc/ssh/sshd_config ‘’OR’’ ssh_config SSHD configuration file (e.g., to change login options or assigned port numbers)
get file Download a file to a local computer
put file Upload a file to a remote computer
rsync -a /home /backups/ Synchronize /home to /backups/home
rsync -avz /home server:/backups/ Synchronize files/directories between the local and remote system with compression enabled
scp -r server:/var/www /tmp Copy all files and directories recursively from server to the current system's /tmp folder.
scp file" server:/tmp Copy file to a remote server (e.g., into the tmp folder)
scp file" server:/tmp Secure copy file.txt to the /tmp folder on server
scp us­er@ho­st:remote lo­cal Copy file from host to local machine
scp server:/var/www/*.html /tmp Copy *.html files from server to the local /tmp folder.
ssh -i Open an SSH client; grant user access to SSH client
ssh -p [port user@host Connect to a remote machine or server through a specified port.
ssh -V Display SSH version installed on the machine
ssh user@host Connect to host as user
ssh user@host Connect to a remote machine or server based on a valid username and hostname or IP address.
SSH user@ip_address OR host Enables SSH login or sign-in to a remote Linux machine by specifying the machine's username and IP address.
ssh host Connect to host as user via SSH port (default port 22)
ssh-copy-id -i .ssh/keyfilename.pub user@hostname Copy public SSH key to remote server
ssh-copy-id user@host Add current user’s key to host to enable keyed or passwordless login
ssh-keygen -t ed25519 -f ~/.ssh/[filename] -C “[optional comment]” Generate SSH key on client computer
sudo nano /etc/ssh/sshd_config, PasswordAuthentication no Disable SSH password login (set PasswordAuthentication to ‘no’, PermitRootLogin to ‘no’, PubkeyAuthentication to ‘yes’)
sudo systemctl reload sshd Restart SSH server
systemctl status sshd Show status of SSH server on host machine
telnet host Uses telnet's default port 23 to connect to a target hostname, remote machine, or server.



3 See also