Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux Network Management and attribute Command

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

I. Linux network management commands

1.Ifconfig command

Ifconfig displays current network information

Format: ifconfig [INTERFACE]

Common options:

-a: view all information

Ifconfig IFACE up | down enabled | disable the interface of a network card

Ifconfig interface [aftype] options | address...

# ifconfig IFACE IP/mask [up]

# ifconfig IFACE IP netmask MASK

Enable promiscuous mode: [-] promisc

Note: takes effect immediately after it is enabled. It will not take effect again when it is turned on again!

Eg: disable the eth2 interface

[root@localhost ~] # ifconfig eth2 down [root@localhost ~] # ifconfig / / you can see that eth2 no longer shows eth0 Link encap:Ethernet HWaddr 00:0C:29:7B:65:71 inet addr:172.16.249.202 Bcast:172.16.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fe7b:6571/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:159414 errors:0 dropped:0 overruns:0 frame:0 TX packets:4673 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12952278 (12.3 MiB) TX bytes:666573 (650.9 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: :: 116128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0b) TX bytes:0 (0.0b)

2.Route command

Common options:

-n: view routing table information

Format: route add | del [- net |-host] target [netmask Nm] [gw Gw] [[dev] If]

Add | del

-net: add | Delete a network route (i.e. add a network segment)

-host: add | Delete a host route

-gw: add | Delete gateway

-netmask: add | Delete subnet mask

Default: add | Delete default route

Eg1: add a host route to eth0 that is 192.168.1.3 and the default gateway is 172.16.0.1

[root@localhost ~] # route add-host 192.168.1.3 gw 172.16.0.1 dev eth0 [root@localhost ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.1.3 172.16.0.1 255.255.255.255 UGH 000 eth0192.168.27.0 0.0.0.0 255.255.255.0 U 00 0 eth2169.254.0.0 0.0.0.0 255.255.0.0 U 1002 00 eth0169.254.0.0 0.0.0.0 255.255.0.0 U 1003 00 eth2172.16.0.0 0.0.0.0 255.255.0.0 U 00 eth00.0.0.0 172.16.0.1 0.0.0.0 UG 000 eth0 delete 192.168.1.3 this route [root@localhost ~] # route del-host 192.168.1.3 [root@localhost ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.27.0 0.0.0.0 255.255.255.0 U 00 0 eth2169.254.0.0 0.0.0.0 255.255.0.0 U 1002 00 eth0169.254.0.0 0.0.0.0 255.255.0.0 U 1003 00 eth2172.16.0.0 0.0 .0.0 255.255.0.0 U 00 eth00.0.0.0 172.16.0.1 0.0.0.0 UG 00 eth0 [root@localhost ~] # Delete this routing entry [root@localhost ~] # route del-net 192.168.0.0amp24 [root@localhost ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.27.0 0.0.0.0 255.255.255.0 U 00 0 eth2169.254.0.0 0.0.0.0 255.255.0.0 U 1002 00 eth0169.254.0.0 0.0.0.0 255.255.0.0 U 1003 00 eth2172.16.0.0 0.0.0.0 255.255.0.0 U 00 eth00.0.0.0 172.16.0.1 0.0.0 UG 00 eth0 or [root@localhost ~] # route del-net 192.168.0.0 netmask 255.255.255. 0 Eg2: add a network route to the eth0 interface as 192.168.0.0. The default gateway is 172.16.0.1 [root@localhost ~] # route add-net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 dev eth0 [root@localhost ~] # route add-net 192.168.0.0 dev eth0 24 gw 172.16.0.1 dev eth0

3.Netstat command

1 >. Show network connections:

Format: netstat [--tcp |-t] [--udp |-- raw |-w] [--listening |-l] [--all |-a] [--numeric |-- numeric-hosts] [--numeric-ports] [--numeric-ports] [--symbolic |-N] [--extend |-e [--extend |-e]]

Common options:

-t: related to tcp protocol

-u: related to udp protocol

-l: listening sockets / / often followed by the-tfurowu option

-p: print information

-e: extended information

-n: display in digital form

-p: displays relevant pid information

Eg: digitally shows which ports the tcp protocol listens on the current host and prints out [root@chang ~] # netstat-tnlpActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0 0 root@chang 22 0 0 0 * LISTEN 1821/sshd tcp 0 0127.0.0.1 LISTEN 2181/sshd tcp 631 0.0.0.0 LISTEN 2181/sshd tcp * LISTEN 1612/cupsd tcp 0 0127.0.0.1 LISTEN 2181/sshd tcp 0 0 0 LISTEN 1478/rpcbind tcp 50982 0 0 0 LISTEN 1580/rpc.statd tcp 0 0 0 15 0 0 0:: 22 : * LISTEN 1821/sshd tcp 0 0:: 1 LISTEN 631: * LISTEN 1612/cupsd tcp 0 0:: 1:25 1935/master tcp 0 0: 35321: * LISTEN 1580/rpc.statd tcp 0 0:: 1 LISTEN 2181/sshd tcp 0 0 10: 111 :: * LISTEN 1478/rpcbind

2 >. Display routing information

Format: netstat {--route |-r} [--numeric |-n] [--numeric-hosts] [--numeric-ports] [--numeric-ports]

Common options:

-r: displays the kernel routing table

-n: display in digital format

3 >. Display interface statistics

Netstat {--interfaces |-I |-I} [iface] [- all |-a] [--extend |-e] [--program |-p]

Common options:

-I: displays all interface information

-I IFACE: displays multi-specified interface information

II. Linux Network Properties Command

1.Ip command

Format: ip [OPTIONS] OBJECT {COMMAND | help}

OBJECT: = {link | addr | route}

Ip link-network device configuration

Set DEVICE {up | down} Activation | disable an API

Show DEVICE

Show up: only interfaces that are active are displayed

Ip address-protocol address management

Ip addr {add | del} IFADDR dev STRING

[label LABEL]: indicates the alias of the network card when adding an address

[scope {global | link | host}]: indicates the scope

Global: globally available

Link: only links are available

Host: available locally

Ip address show-look at protocol addresses

[dev DEVICE]

[label PATTERN]

[primary and secondary]

Ip address flush-flush protocol addresses

Use the same format as show

Ip route-routing table management

Ip route add

Add Route: ip route add TARGET via GW dev IFACE src SOURCE_IP

TARGET:

Host routing: IP

Network routing: NETWORK/MASK

Add Gateway: ip route add defalt via GW dev IFACE

Ip route delete

Delete route: ip route del TARGET

Ip route show

Ip route flush

[dev IFACE]

[via PREFIX]

2.ss command

Format: ss [options] [FILTER]

Common options:

-t: related to tcp protocol

-u: related to udp protocol

-w: display bare sockets

-x: unix sock related

-l: connection for listening statu

-a: all

-n: display in digital format

-p: related programs and their pid

-e: information about extend

-m: memory usage

-o: timer information

FILTER: = [state TCP-STATE] [EXPRESSION]

EXPRESSION:

Dport =

Sport =

Supplement: common status of tcp

LISTEN: monitoring

EATABLISHED: established connection

FIN_WAIT_1

FIN_WAIT_2

SYN_SENT

SYN_RECV

CLOSE

The ss command is similar to the netstat command, but it is better to use the ss command when the current number of connections is large.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report