At It's FOSS we are not talking about the "command line aspect" of Linux every day. Basically, I'm more focused on the desktop side of Linux. But some of your readers in-house surveys (It's FOSS newsletter subscribers only) point out that you also want to learn some command-line tricks. The Quick check table is also popular with most readers.
To do this, I edited a list of basic network commands in Linux. It's not a tutorial that teaches you how to use these commands, but rather a collection of commands and their short explanations. So, if you've already used these commands, you can use it to quickly remember commands.
You can add this page as a bookmark for quick reference, or output a PDF version for offline use.
I had this list of Linux network commands when I was a student of communication systems engineering. It helped me get a high score on the computer network course. Hopefully it will help you in the same way.
Linux Basic Network Command list
I use FreeBSD on a computer network course, but these UNIX commands should also work on Linux.
Connectivity of
ArpARP is used to convert an IP address to an Ethernet address. The root user can add and remove ARP records. It can be useful to delete ARP records when they are contaminated or wrong. The ARP record that is explicitly added by root is permanent-the proxy setting is also. The ARP table is stored in the kernel and is dynamically manipulated. ARP records are cached and typically expire after 20 minutes and are deleted.
arp -a
: Prints the ARP table.
arp -s <ip_address> <mac_address> [pub]
: Adds a record to the table.
arp -a -d
: Deletes all records in the ARP table.
Routing
netstat -r
: Prints the routing table. The routing table is stored in the kernel and is used by the IP layer to route packets to non-local networks.
route add
: The route command is used to add static (manually specified rather than dynamic) routing paths to the routing table. All traffic from that PC to that ip/subnet goes through the specified gateway IP. It can also be used to set a default route. For example, using 0.0.0.0 at the ip/subnet, you can send all packages to a specific gateway.
routed
: The BSD daemon that controls dynamic routing. Start up at boot time. It runs the RIP routing protocol. Only the root user is available. You cannot run it without root privileges.
gated
: Gated is another routing daemon that uses RIP protocol. It supports both OSPF, EGP, and RIP protocols. Only the root user is available.
traceroute
: The route used to track IP packets. It adds 1 hops each time it sends a packet, allowing all gateways from the source address to the destination to return a message.
netstat -rnf inet
: Displays the routing table for IPV4.
sysctl net.inet.ip.forwarding=1
: Enable packet forwarding (turn the host into a router).
route add|delete [-net|-host] <destination> <gateway>
: (e.g. route add 192.168.20.0/24 192.168.30.4
) add a route.
route flush
: Removes all routes.
route add -net 0.0.0.0 192.168.10.2
: Adds a default route.
routed -Pripv2 -Pno_rdisc -d [-s|-q]
: Run the routed daemon, use the RIPV2 protocol, do not enable ICMP Autodiscover, run in the foreground, supply mode, or Quiet mode.
route add 224.0.0.0/4 127.0.0.1
: Defines a multicast route for the local address. (LCTT: The original is doubtful)
rtquery -n (LCTT: Added host parameter): Queries the RIP daemon on the specified host (manually updating the routing table).
Other
nslookup
: Query to DNS server, turn IP to name, or vice versa. For example, a nslookup facebook.com
facebook.com IP is given.
ftp (LCTT: The original water should be a clerical error): Transfer files to the specified host. You can usually log in using the login name "anonymous" and the password "guest".
rlogin -l (LCTT: Added the host parameter): Log on to the host with a virtual terminal like Telnet.
Important Documents
/etc/hosts
: The mapping of the domain name to the IP address.
/etc/networks
: The mapping of the network name to the IP address.
/etc/protocols
: The mapping of the Protocol name to the protocol number.
/etc/services
: TCP/UDP The service name to the port number mapping.
Tools and network performance analysis
ifconfig <interface> <address> [up]
: Start the interface.
ifconfig <interface> [down|delete]
: Stops the interface.
ethereal &
: Opens in the background ethereal
rather than the foreground.
tcpdump -i -vvv
: A tool for crawling and analyzing packages.
netstat -w [seconds] -I [interface]
: Displays network settings and statistics.
udpmt -p [port] -s [bytes] target_host
: Send UDP traffic.
udptarget -p [port]
: Receives UDP traffic.
tcpmt -p [port] -s [bytes] target_host
: Sends TCP traffic.
tcptarget -p [port]
: Receives TCP traffic.
Switch
ifconfig sl0 srcIP dstIP
: Configure a serial interface (first executed before slattach -l /dev/ttyd0
, then executed sysctl net.inet.ip.forwarding=1
)
telnet 192.168.0.254
: Access the switch from a host in the subnet.
sh ru
or show running-configuration
: View the current configuration.
configure terminal
: Enter configuration mode.
exit
: Exits the current mode. (LCTT: The original is doubtful)
Vlan
vlan n
: Create a VLAN with an ID of N.
no vlan N
: Delete the VLAN with ID N.
untagged Y
: Add port Y to VLAN N.
ifconfig vlan0 create
: Create the Vlan0 interface.
ifconfig vlan0 vlan_ID vlandev em0
: Add Em0 to Vlan0 Interface (LCTT) and set tag as ID.
ifconfig vlan0 [up]
: Enables the virtual interface.
tagged Y
: Adds tag frame support for Port Y of the current VLAN.
Udp/tcp
socklab udp
: Run with the UDP protocol socklab
.
sock
: Creates a UDP socket, which is equivalent to the input sock udp
and bind
.
sendto <Socket ID> : Sends a packet.
recvfrom <Socket ID> <byte #>
: Receives data from a socket.
socklab tcp
: Run using the TCP protocol socklab
.
passive
: Creates a passive mode socket, which is equivalent to,,, socklab
sock tcp
bind
listen
.
accept
: Accepts incoming connections (can be performed before or after initiating a connection).
connect : Equivalent socklab
,, sock tcp
bind
, connect
.
close
: Closes the connection.
read <byte #>
: Reads n bytes from the socket.
write
: (for example, write ciao
, write #10
) write "ciao" or 10 bytes to a socket.
nat/Firewall
rm /etc/resolv.conf
: Prohibit address resolution to ensure that your filtering and firewall rules work correctly.
ipnat -f file_name
: Writes the filter rule to the file.
ipnat -l
: Displays the list of rules for the activity.
ipnat -C -F
: Reinitialize the rule table.
map em0 192.168.1.0/24 -> 195.221.227.57/32 em0
: Maps an IP address to an interface.
map em0 192.168.1.0/24 -> 195.221.227.57/32 portmap tcp/udp 20000:50000
: A mapping with a port number.
ipf -f file_name
: Writes the filter rule to the file.
ipf -F -a
: Resets the rules table.
ipfstat -I
: Lists the active status entries when combined with the-s option (LCTT: The original is in doubt).
You have to understand the basics of Linux network commands