Linux study notes - network commands

1.12. Network commands

 

1.12.1.write

Send a message to the specified user, end with Ctrl+D to save and send

 

Send a message to test user as root user

[root@localhost cn]# write test

i missing you.

[root@localhost cn]#

 

message received by test

[test@localhost ~]$

Message from [email protected] on pts/0 at 21:58 ...

i missing you.

EOF

 

When this command sends a message, the user must be online to send it, otherwise it will be sent.

 

You can use w to see which users are online

 

 

1.12.2.wall

English willing: write all

send a broadcast message

Syntax: wall [message]

 

After sending, you will receive a copy

[root@localhost cn]# wall hello world!

[root@localhost cn]#

Broadcast message from [email protected] (pts/0) (Fri Apr 27 22:01:56 2018):

 

hello world!

 

The test user also receives a copy

Broadcast message from [email protected] (pts/0) (Fri Apr 27 22:01:56 2018):

 

hello world!

 

 

 

1.12.3.ping

Test network connectivity

 

ping option IP address

 

-c specifies the number of times to send

 

 

By default, it will not stop, and it will always send data packets. It must be Ctrl+C to end.

[root@localhost cn]# ping 192.168.1.1

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.

64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.913 ms

64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.54 ms

64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.804 ms

64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.797 ms

^C

--- 192.168.1.1 ping statistics ---

10 packets transmitted, 10 received, 0% packet loss, time 9006ms

rtt min/avg/max/mdev = 0.735/0.947/1.542/0.225 ms

 

 

packet loss The packet loss rate is used to judge the network quality.

 

Use the -c option to specify the number of times to send

[root@localhost cn]# ping -c 2 192.168.1.1

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.

64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.856 ms

64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.874 ms

 

--- 192.168.1.1 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1000ms

rtt min/avg/max/mdev = 0.856/0.865/0.874/0.009 ms

[root@localhost cn]#

 

 

1.12.4.ifconfig

English original meaning: interface configure

 

View and set network card information

 

Syntax: ifconfig network card name IP address

 

View network card

[root@localhost cn]# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.200  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::87e1:e178:41b3:d5b1  prefixlen 64  scopeid 0x20<link>

        ether 00:15:5d:01:65:06  txqueuelen 1000  (Ethernet)

        RX packets 4592  bytes 859283 (839.1 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 1655  bytes 160274 (156.5 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 1  (Local Loopback)

        RX packets 5  bytes 560 (560.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 5  bytes 560 (560.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

lo loopback card

RX packets receive data packets and size

TX packets send data packets and size

 

 

Set IP, temporary change, non-permanent modification

example:

ifconfig eth0 192.168.1.202

 

 

1.12.5.mail

View Send Email

 

This is better than write in that it does not require the user to be online.

 

End with Ctrl+D to save and send email

 

 

The use of the mail command requires the installation of the mailx installation package

[root@localhost cn]# yum install mailx

 

 

Send an email to root user

[root@localhost cn]# mail root

Subject: test subject

hi.

EOT

 

View sent mail

[root@localhost cn]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 1 message 1 new

>N  1 root                  Fri Apr 27 22:18  18/610   "test subject"

 

N means unread

1 is the ID of the email

root is the sending user

send time

mail title

 

Enter the mail view interactive command, start the command with &

 

type help

Can view command help

& help

               mail commands

type <message list>             type messages

next                            goto and type next message

from <message list>             give head lines of messages

headers                         print out active message headers

delete <message list>           delete messages

undelete <message list>         undelete messages

save <message list> folder      append messages to folder and mark as saved

copy <message list> folder      append messages to folder without marking them

write <message list> file       append message texts to file, save attachments

preserve <message list>         keep incoming messages in mailbox even if saved

Reply <message list>            reply to message senders

reply <message list>            reply to message senders and all recipients

mail addresses                  mail to specific recipients

file folder                     change to another folder

quit                            quit and apply changes to folder

xit                             quit and discard changes made to folder

!                               shell escape

cd <directory>                  chdir to directory or home if none given

list                            list names of all available commands

 

A <message list> consists of integers, ranges of same, or other criteria

separated by spaces.  If omitted, mail uses the last message typed.

&

 

Enter email ID 1 to view email content

& 1

Message  1:

From [email protected]  Fri Apr 27 22:18:17 2018

Return-Path: <[email protected]>

X-Original-To: root

Delivered-To: [email protected]

Date: Fri, 27 Apr 2018 22:18:17 +0800

To: [email protected]

Subject: test subject

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: [email protected] (root)

Status: R

 

hi.

 

&

 

Enter h to go back to the mailing list

After reading the email, N is not displayed

& h

>   1 root                  Fri Apr 27 22:18  18/610   "test subject"

&

 

Enter d mail id, delete mail

& d 1

& h

No applicable messages

&

 

Enter q to exit

 

& q

[root@localhost cn]#

 

 

 

1.12.6.last

List all current and past users who have logged into the system, including system restarts

 

[root@localhost cn]# last

User Login terminal Whether the login IP login time is still online/logout time, duration

test     pts/1        192.168.1.101    Fri Apr 27 21:57   still logged in

root     pts/0        192.168.1.101    Fri Apr 27 21:20   still logged in

reboot   system boot  3.10.0-693.el7.x Fri Apr 27 19:50 - 22:28  (02:37)

test pts / 1 192.168.1.101 Thu Apr 26 23:22 - 23:22 (00:00)

test pts / 1 192.168.1.101 Thu Apr 26 23:07 - 23:22 (00:15)

reboot   system boot  3.10.0-693.el7.x Wed Apr 25 21:43 - 22:28 (2+00:45)

root     pts/0        192.168.1.101    Tue Apr 24 20:19 - crash (1+01:23)

 

wtmp begins Sun Apr 22 16:10:16 2018

 

When the user is listed as reboot, it means the system has restarted.

 

 

 

1.12.7.lastlog

Last login information

List all user information, list the last login information

[root@localhost cn]# lastlog

Username         Port     From             Latest

root             pts/0    192.168.1.101    Fri Apr 27 21:20:22 +0800 2018

bin                                        **Never logged in**

daemon                                     **Never logged in**

adm                                        **Never logged in**

lp                                         **Never logged in**

sync                                       **Never logged in**

shutdown                                   **Never logged in**

halt                                       **Never logged in**

mail                                       **Never logged in**

operator                                   **Never logged in**

games                                      **Never logged in**

ftp                                        **Never logged in**

nobody                                     **Never logged in**

systemd-network                            **Never logged in**

dbus                                       **Never logged in**

polkitd                                    **Never logged in**

postfix                                    **Never logged in**

sshd                                       **Never logged in**

test pts / 1 192.168.1.101 Fri Apr 27 21:57:39 +0800 2018

 

-u user ID View the login information of a user

 

[root@localhost cn]# lastlog -u 0

Username         Port     From             Latest

root             pts/0    192.168.1.101    Fri Apr 27 21:20:22 +0800 2018

[root@localhost cn]# lastlog -u 1000

Username         Port     From             Latest

test pts / 1 192.168.1.101 Fri Apr 27 21:57:39 +0800 2018

 

How to check user ID?

[root@localhost cn]# cat /etc/passwd

root:x:0:0:root:/root:/bin/bash

 

1.12.8.traceroute

Display the path of the packet to the host

 

This command requires the package traceroute to be installed

[root@localhost cn]# yum install traceroute

 

[root@localhost cn]# traceroute www.baidu.com

traceroute to www.baidu.com (119.75.213.61), 30 hops max, 60 byte packets

 1  gateway (192.168.1.1)  0.525 ms  0.503 ms  1.113 ms

 2  * * *

 3  * * *

 4 10.144.11.202 (10.144.11.202) 1.729 ms 1.720 ms 1.709 ms

 5 14.197.242.145 (14.197.242.145) 4.232 ms * 4.900 ms

 6 14.197.248.253 (14.197.248.253) 7.647 ms 14.197.248.241 (14.197.248.241) 5.957 ms 14.197.248.253 (14.197.248.253) 6.582 ms

 7 14.197.252.197 (14.197.252.197) 45.213 ms 14.197.252.189 (14.197.252.189) 44.424 ms 14.197.252.37 (14.197.252.37) 45.195 ms

 8 14.197.252.54 (14.197.252.54) 45.174 ms 45.180 ms 14.197.252.50 (14.197.252.50) 45.170 ms

 9 14.197.149.178 (14.197.149.178) 45.162 ms 14.197.149.182 (14.197.149.182) 41.744 ms *

10  * * *

11 * 182.61.253.126 (182.61.253.126) 53.336 ms 42.238 ms

12  * * *

13  * * *

14  * * *

15  * * *

16  * * *

17  * * *

18  * * *

19  * * *

20  * * *

21  * * *

22  * * *

23  * * *

24  * * *

25  * * *

26  * * *

27  * * *

28  * * *

29  * * *

30  * * *

 

 

1.12.9.netstat

net status network status

 

Display network related information

 

-t TCP protocol, with handshake, confirm receipt.

-u UDP protocol, no handshake, just throw a message in the past, whether you receive it or not

-l listen

-r route

-n show IP address and port number

 

example:

netstat –tlun View the port that the machine is listening on

 

[root@localhost cn]# netstat -tlun

Active Internet connections (only servers)

Protocol receiving transmission distance, 0 means normal

Proto Recv-Q Send-Q Local Address           Foreign Address         State

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN

tcp6       0      0 :::22                   :::*                    LISTEN

tcp6       0      0 ::1:25                  :::*                    LISTEN

[root@localhost cn]#

 

TCP only listens to LISTEN, UDP does not.

 

netstat -an View all network connections of the machine

-a all means

 

[root@localhost cn]# netstat -an

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address           Foreign Address         State

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN

tcp        0      0 192.168.1.200:22        192.168.1.101:52591     ESTABLISHED

tcp        0     36 192.168.1.200:22        192.168.1.101:51745     ESTABLISHED

tcp        0      0 192.168.1.200:22        192.168.1.101:52592     ESTABLISHED

tcp        0      0 192.168.1.200:22        192.168.1.101:51748     ESTABLISHED

tcp6       0      0 :::22                   :::*                    LISTEN

tcp6       0      0 ::1:25                  :::*                    LISTEN

raw6       0      0 :::58                   :::*                    7

Active UNIX domain sockets (servers and established)

Proto RefCnt Flags       Type       State         I-Node   Path

unix  2      [ ACC ]     STREAM     LISTENING     19078    public/flush

unix  2      [ ACC ]     STREAM     LISTENING     19093    public/showq

 

ESTABLISHED Connected state

 

 

netstat –rn View the local routing table

The gateway address can be viewed

[root@localhost cn]# netstat -rn

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0

192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

[root@localhost cn]#

 

1.12.10.setup

Configure the network

The set of management tools that comes with red hat does not exist in other versions of Linux.

can support:

Firewall configuration

Network Configuration

system service

Verify configuration

 

install setuptool

[root@localhost cn]# setup

-bash: setup: command not found

 [root@localhost cn]# yum install setuptool

Loaded plugins: fastestmirror

 

Enter the setup command directly to enter the configuration tool

[root@localhost cn]# setup

 

1.12.11.mount

mount

mount [-t filesystem] device filename mount point

 

 

mount the disc

mount –t iso9660 /dev//sr0 /mnt/cdrom

 

iso9660

Indicates the CD-ROM file system, this is fixed. The system knows that, in fact, it is not necessary to write.

 

Device file name, fixed, the CD is /dev/sr0, it can also be specified as a soft link /dev/cdrom

 

[root@localhost dev]# ll /dev/cdrom

lrwxrwxrwx. 1 root root 3 Apr 27 23:11 /dev/cdrom -> sr0

 

 

1. Installation CD

 

2. Create a mount point

[root@localhost /]# mkdir /mnt/cdrom

 

3. Mount

[root@localhost dev]# mount /dev/cdrom /mnt/cdrom

mount: /dev/sr0 is write-protected, mounting read-only

[root@localhost dev]#

The prompt message indicates that the CD is read-only and is nearly mounted as a read-only file

 

You can access it by entering the mount point. /dev/cdrom is a device that cannot be accessed and cannot be accessed.

 

[root@localhost dev]# cd /mnt/cdrom

[root@localhost cdrom]# ls

autorun.inf  boot  bootmgr  bootmgr.efi  efi  setup.exe  sources  support  upgrade

[root@localhost cdrom]#

 

 

4. Uninstall

In Linux, when you mount and use it, you must manually uninstall it yourself

 

When the mount point directory is installed, it cannot be uninstalled, and the following prompts: Need to exit the mount point directory

[root@localhost cdrom]# umount /mnt/cdrom

umount: /mnt/cdrom: target is busy.

        (In some cases useful info about processes that use

         the device is found by lsof(8) or fuser(1))

[root@localhost cdrom]#

 

After uninstalling, the contents of the directory /mnt/cdrom are gone.

When unmounting, you can specify the mount point, and you can also specify the device: umount /dev/sr0

[root@localhost /]# umount /mnt/cdrom

[root@localhost /]# ls /mnt/cdrom

[root@localhost /]#

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325960358&siteId=291194637