Organize the list of commonly used network commands under Linux for quick and easy reference.
ping
telnet
7 - echo port
25 - SMTP, used to send emails
79 - Finger provides information about other users on the network information.
ARP is used to translate an IP address to an Ethernet address. The root user can add and delete ARP records. Deleting ARP records is useful when they are contaminated or incorrect. ARP records explicitly added by root are permanent - as are those set by the proxy. The ARP table is stored in the kernel and is manipulated dynamically. ARP records are cached and typically expire after 20 minutes and are deleted.
arp -a: Print ARP table.
arp -s
arp -a -d: Delete all records in the ARP table.
netstat -r: Print routing table. Routing tables are kept in the kernel and are used by the IP layer to route packets to non-local networks.
route add: The route command is used to add a static (manually specified rather than dynamic) routing path to the routing table. All traffic from this PC to that IP/subnet will go 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 would send all packets to a specific gateway.
routed: BSD daemon that controls dynamic routing. Start at boot. It runs the RIP routing protocol. Available only to root user. You cannot run it without root privileges.
gated: gated is another routing daemon that uses the RIP protocol. It supports both OSPF, EGP and RIP protocols. Available only to root user.
traceroute: used to trace the route of IP packets. It increments the hop count by 1 each time it sends a packet, causing all gateways from the source address to the destination to return the message.
netstat -rnf inet: Display the IPv4 routing table.
sysctl net.inet.ip.forwarding=1: Enable packet forwarding (turn the host into a router).
route add|delete [-net|-host]
route flush: delete all routes.
route add -net 0.0.0.0 192.168.10.2: Add a default route.
routed -Pripv2 -Pno_rdisc -d [-s|-q]: Run the routed daemon, using the RIPv2 protocol, without ICMP autodiscovery enabled, in the foreground, provisioning mode or quiet mode.
route add 224.0.0.0/4 127.0.0.1: Defines a multicast route for the local address.
rtquery -n
nslookup: Query the DNS server to convert IP to name, or vice versa. For example, nslookup facebook.com will give you the IP of facebook.com.
ftp
rlogin -l
/etc/hosts: Domain name to IP address mapping.
/etc/networks: Mapping of network names to IP addresses.
/etc/protocols: Mapping of protocol names to protocol numbers.
/etc/services: TCP/UDP service name to port number mapping.
ifconfig
ifconfig
ethereal &: Open ethereal in the background instead of the foreground.
tcpdump -i -vvv: Tool for capturing and analyzing packages.
netstat -w [seconds] -I [interface]: Display network settings and statistical information.
udpmt -p [port] -s [bytes] target_host: Send UDP traffic.
udptarget -p [port]: Receive UDP traffic.
tcpmt -p [port] -s [bytes] target_host: Send TCP traffic.
tcptarget -p [port]: Receive TCP traffic.
ifconfig sl0 srcIP dstIP: Configure a serial interface (execute slattach -l /dev/ttyd0 before, and then execute sysctl net.inet.ip.forwarding=1)
telnet 192.168.0.254: Access the switch from a host on the subnet.
sh ru or show running-configuration: View the current configuration.
configure terminal: Enter configuration mode.
exit: Exit the current mode.
vlan n: Create a VLAN with ID n.
no vlan N: Delete the VLAN with ID n.
untagged Y: Add port Y to VLAN n.
ifconfig vlan0 create: Create vlan0 interface.
ifconfig vlan0 vlan_ID vlandev em0: Add em0 to the vlan0 interface and set the tag to ID.
ifconfig vlan0 [up]: Enable virtual interface.
tagged Y: Add tagged frame support for port Y of the current VLAN.
socklab udp: Run socklab using UDP protocol.
sock: Creates a UDP socket, equivalent to typing sock udp and bind.
sendto
recvfrom
socklab tcp: Run socklab using TCP protocol.
passive: Create a passive mode socket, equivalent to socklab, sock tcp, bind, listen.
accept: Accept incoming connections (can be executed before or after initiating incoming connections).
connect
close: Close the connection.
read
write: (e.g., write ciao, write #10) Write "ciao" or 10 bytes to the socket.
rm /etc/resolv.conf: Disable address resolution to ensure your filtering and firewall rules work correctly.
ipnat -f file_name: Write filtering rules to a file.
ipnat -l: Displays the list of active rules.
ipnat -C -F: Reinitialize the rule table.
map em0 192.168.1.0/24 -> 195.221.227.57/32 em0: Maps IP addresses to interfaces.
map em0 192.168.1.0/24 -> 195.221.227.57/32 portmap tcp/udp 20000:50000: Mapping with port number.
ipf -f file_name: Write filtering rules to a file.
ipf -F -a: Reset the rule table.
ipfstat -I: Lists active status entries when used with the -s option
The above is the detailed content of Summary of basic network commands in Linux. For more information, please follow other related articles on the PHP Chinese website!