Home  >  Article  >  Operation and Maintenance  >  Summary of basic network commands in Linux

Summary of basic network commands in Linux

巴扎黑
巴扎黑Original
2017-08-17 10:28:032062browse

Organize the list of commonly used network commands under Linux for quick and easy reference.

Connectivity

ping : Sends an ICMP echo message (a packet) to the host. This may keep sending until you press Control-C. A ping means a packet is sent out from your machine via ICMP and echoed back at the IP layer. Ping tells you if the other host is running.

telnet [port]: Communicate with the host on the specified port. The default telnet port is 23. Press Control-] to exit telnet. Some other commonly used ports are:

7 - echo port

25 - SMTP, used to send emails

79 - Finger provides information about other users on the network information.

ARP

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 [pub]: Add a record to the table.

arp -a -d: Delete all records in the ARP table.

Routing

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] : (such as route add 192.168.20.0/24 192.168.30.4) Add a route.

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 : Query the RIP daemon on the specified host (manually update the routing table).

Others

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 [port]: Transfer files to the specified host. Usually you can use the login name "anonymous" and the password "guest" to log in.

rlogin -l : Use a virtual terminal similar to telnet to log in to the host.

Important files

/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.

Tools and Network Performance Analysis

ifconfig

[up]: Start the interface.

ifconfig [down|delete]: Stop the interface.

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.

Switch

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

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.

UDP/TCP

socklab udp: Run socklab using UDP protocol.

sock: Creates a UDP socket, equivalent to typing sock udp and bind.

sendto : Send data packet.

recvfrom : Receive data from the socket.

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 : Equivalent to socklab, sock tcp, bind, connect.

close: Close the connection.

read : Read n bytes from the socket.

write: (e.g., write ciao, write #10) Write "ciao" or 10 bytes to the socket.

NAT/Firewall

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn