Linux-related network commands

Source: Internet
Author: User

1. The OSI seven-layer model and the TCP/IP four-layer model

OSI seven-layer model

TCP/IP four layer model

2. Brief description of Iproute family order

IP command:

  IP [OPTIONS] OBJECT {command|help}

  IP Link:network device configuration.

    IP Link Set DEV: Modify device properties

1) up or down: Enable or disable the interface; example, IP link set eth1 up/down

2) multicast on or multicast off: Enable or disable multicast function, example, IP link set eth1 multicast on/off

3) name name: rename interface; example, IP link set eth1 name eth666

4) MTU Number: Sets the size of the MTU, by default, (MTU, Maximum transmission unit, the maximum packet size that can be sustained on a certain layer of communication protocol; the larger the MTU, the larger the valid packets are loaded)

5) Netns PID: Moves the specified NIC to the specified virtual network (the local system will not see the NIC)

Example, IP netns add mynet (Building a virtual network mynet)

IP link Set eth1 netns mynet (add interface eth1 to virtual network mynet)

IP netns exec mynet IP link show (view interface information for virtual network mynet)

IP netns del mynet (delete virtual network)

    IP link show/list: Display device properties

    IP linkhelp: show brief usage assistance

  IP netns:Manage network namespaces.

Interpretation: Netns is a project that provides network virtualization in Linux, using NETNS to virtualize multiple network environments locally, each virtual network space is independent of the current system's network space, and network devices and iptables rules are independent.

1) IP Netns list: List all Netns

2) IP netns add NAME: Create the specified netns

3) IP netns del NAME: delete the specified netns

4) IP netns exec NAME command: Run the commands in the specified netns

5) IP netns help: show brief use assistance
6) Exit: Exit Virtual network

  IP Address:protocol address management.

1) IP address add ifaddr dev IFACE: Add one more IP to the specified NIC, example, IP address add 192.168.10.2/24 dev eth1

[Label NAME]: Specifies the interface alias for additional addresses; example, IP address add 10.1.1.10/8 dev eth1 label eth1:0

[Broadcast address]: Broadcast addresses, will be automatically calculated according to IP and netmask;

[Scope Scope_value]:global: Globally available; Link: interface available; Host: only native available

2) IP address delete ifaddr dev IFACE: remove IP from interface; example, IP address delete 10.1.1.10/8 dev eth1

3) IP address list/show [IFACE]: Displays the address information of the interface; example, IP address SHOW,IP address list eth1

4) IP address flush dev IFACE: Clears all address information for the interface; example, IP address flush dev eth1

  IP route:routing Table management.

1) IP route add TYPE PREFIX via GW [Dev IFACE] [src source_ip]: Add routing information;
Example, IP route add 10.0.2.0/24 via 10.0.1.11 (the next hop address to the 10.0.2.0/24 network is 10.0.1.11)
IP route add 10.0.2.0/24 dev eth0 (via interface eth0 reach 10.0.2.0/24 network)
IP route add 192.168.1.0/24 via 10.0.0.1 Dev eth1 (arrival 192.168.1.0/24 network must pass the next hop address eth1 of the interface 10.0.0.1)

IP route add 192.168.1.0/24 via 10.0.0.1 dev eth1 src 10.0.10.100 (eth1 address via 10.0.10.100 interface, via next hop 10.0.0.1 to reach network 192.168.1.0/ 24; This routed gateway is native)

IP route add defaults via 172.16.0.1 dev eth0 (add default route via Eth0 interface with next hop 172.16.0.1 out)

2) IP route del: Delete routing information

Example, IP route delete 192.168.1.0/24

IP route show: Show routing information

3) IP route flush-flush routing tables

Example, IP route flush 192.168.1.0/24

4) IP route get: Get routing information

Example, IP route get 192.168.0.0/24
SS Command:

Get socket information that displays and netstat similar content, but is more efficient than netstat.

SS [Options] [FILTER]

Options

-T:TCP protocol related connections

-U:UDP Related connections

-W: Show only connections for raw sockets

-L: Displays the connection in the listening state

-A: Connections for all States

-N: Service name not resolved

-P: Shows the process using the socket

-E: Show detailed information

-M: Memory usage
-S: Show socket Usage overview

-O: Timer information

FILTER:
=[state tcp-state] [EXPRESSION]

Tcp-state includes:

LISTEN: Monitoring

ESTABLISEHD: Established connection

Fin_wait_1: Waiting for a remote TCP connection to interrupt the request

Fin_wait_2: Waiting for connection interrupt request from remote TCP

Syn_sent: Client sends request connection

SYN_RECV: server receives request connection

CLOSED: No connection

Example, Ss-tan State established

EXPRESSION:

dport=

sport=

example, Ss-tan ' (Dport =: + or sport =: 22) ' (Note that this command space cannot be omitted)

3, detailed instructions for management tools Htop, Vmstat and other related commands, and examples

Htop

Text-based, interactive process Viewer, primarily for the console or shell, is more user-friendly than the top command, and can be said to be the premium version of top. Linux system by default does not install Htop, need to install itself, you can log on to download the installation or configuration Epel source, through the Yum install Htop installation.

  Use of Htop:

[Email protected] ~]# Htop

A total of four zones are divided:

1) Upper left: Displays information about the CPU (1, 2 of the CPU's cores), physical memory, and the swap partition;

2) Upper right: Displays the number of tasks (task), the average load (load average), and the system's running time from boot to current;

3) Process area: Dynamic display of all processes in the current system;

4) Operation Prompt Area: Displays the shortcut function defined in the F1~F10 function key in the current interface.

  Htop Common function keys:

    F1: View htop usage Instructions

F2: Setting

F3: Search Process

F4: filter, search by keyword

F5: Show tree structure

F6: Choosing a Sort method

F7: Reduce the nice value so that the priority of the corresponding process can be increased

F8: Add nice value, which can reduce the priority of the corresponding process

F9: Kill the selected process

F10: Exit Htop

    /: Search for characters

H: Show Help

L: Show files opened by the process

U: Show all users, and can select a process for a particular user

S: System call that will call the Strace tracing process

T: Show tree structure

H: Show/Hide User threads

I: Reverse the sort order

K: Show/Hide Kernel threads

M: Sort by memory footprint

P: Sort by CPU

T: Sort by run time

Up or down key or PGUP,PGDN: Move selected process

Left or right key or home,end: Move List

Space (blank): Mark/Unmark a process

 Htop Common options:

-D #: Specify the delay time interval

-u UserName: Show only the process of the specified user

-S Colume: Sorting in the specified field

Vmstat

In the specified time interval, dynamic monitoring of the system's virtual memory, process, CPU activity as a whole, is a low-overhead tool. Command format: vmstat [options] [delay [count]].

    Delay: Refresh interval, if not specified, displays only one result;

Count: Number of refreshes, if count is not specified but delay is specified, it will be refreshed.

Common options:

    -A: Show active and inactive memory

-F: Shows the number of fork from system start up to now

-M: Display slab information (slab,linux memory allocation mechanism)

-N: Displays the field names only once at the beginning

-S: Displays memory-related statistics and number of system activities

-D: Display disk-related statistics

-P: Display specified disk partition statistics

-S: Displayed using the specified units. The parameters are K, K, M, M, respectively, representing 1000, 1024, 1000000, 1048576 bytes (bytes). The default unit is K (1024x768 bytes)

-V: Show Vmstat version information

Example:

1 summary information displayed by default

Interval 2 seconds Refresh 1 summary, Total 3 times

Keyword interpretation:

    

4. Use until and while to implement Ping 192.168.0.0/24 respectively

#!/bin/Bashdeclare-I. up=0Declare-I. down=0Declare-I. i=0Declare-I. j=1Trap'Interrupt_trap'Intinterrupt_trap () {Echo "QUIT"    Echo "there is $up IPs being up."    Echo "there is $down IPs being down."Exit1} while[$i-le255]; Do     while[$j-le255]; Do        if[$i-eq255-A $j-eq255]; Then Breakfi        Ping-w1-c1192.168. $i. $j &>/dev/NULL         if[$?-eq0]; Then            Echo "192.168. $i. $j is up." let up++Else            Echo "192.168. $i. $j is down." let down++fiLet J++[$j-eq the] && j=1     DoneLet i++ DoneEcho "there is $up IPs being up."Echo "there is $down IPs being down."

Linux-related network commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.