FreeBSD Network Related commands

Source: Internet
Author: User
Tags syslog nslookup

23.5.1 Ping

Check the online status of the remote system. The ping command sends an ICMP packet to the specified host, which we can use to check the online quality of the network.

Common parameters are as follows:

Parameters Description
-C Count Specifies that you want to count the Count times.
-S size Specify size for each packet.
-T Timeout Specify Time Out times.
-I. Interface If the destination host address is a broadcast address, and we have multiple network interfaces, you can specify which interface to use.

For example, we want to see the online quality of www.freebsd.org:

$ ping www.freebsd.org
ping freefall.freebsd.org (216.136.204.21): Data bytes
bytes from 216.136.204.21:ic Mp_seq=0 ttl=54 time=458.986 ms
bytes from 216.136.204.21:icmp_seq=1 ttl=54-time=502.258 ms bytes from
216. 136.204.21:icmp_seq=2 ttl=54 time=491.489 ms
^c
---freefall.freebsd.org ping statistics---
3 packets Transmitted, 3 packets received, 0% packet loss round-trip
= Min/avg/max/stddev ms

23.5.2 ifconfig

Set or check the network interface. We can use Ifconfig to display all the network interfaces, if you use the parameter-u to display the network interface in use, and-D is a non operational interface.

We can also use Ifconfig to let the network interface operate or deactivate.

Usage:

ifconfig [Down|up] Interface

Let's say we want to disable the network card vr0:

# ifconfig Vr0 Down

We can also use Ifconfig to set the IP address on the network. Suppose you want to set IP to 192.168.0.1, and the subnet mask is 255.255.255.0:

# ifconfig vr0 192.168.0.1 netmask 255.255.255.0

Then use Ifconfig to enable VR0:

# ifconfig Vr0 up

23.5.3 ARP

Displays the ARP address. For example, we want to display the network card number of the 192.168.0.2 machine:

$ arp 192.168.0.1

23.5.4 traceroute

Tracks the path that is used by this machine to a host computer. When we use ping to check the online status of the network, we can use traceroute to check to see which host on the network is having problems if we find that we can't go online.

$ traceroute www.freebsd.org

23.5.5 netstat

Displays network status. We can use Netstat to display the current online situation. For example:

$ netstat-a Active Internet connections (including servers) Proto Recv-q Local address send-q    address     (state) tcp4         0        20    www.ssh         198.z27z4z49.1780 Established tcp4         0        0     *.http          *.*                  LISTEN tcp4          0        0    *.https          *.*                  LISTEN tcp4         0        0    *.smtp            *.*                 LISTEN tcp4         0        0     *.ssh           *.*                  LISTEN tcp4          0        0    *.pop3           *.*                  LISTEN udp4         0         0    *.syslog        *.* udp6         0        0    *. syslog        *.* Active UNIX domain sockets address    Type & nbsp;   recv-q send-q      inode      Conn Refs Addr cd864e00 dgram      0        0   
       0      cd84ef0     0 cd864fc0 CD864FC0 dgram      0        0           0      cd84ef0     0           0

We can see from the above results that a user is currently using SSH to connect to our website. By the above table, we can see the service we provide and what is the current usage situation. If we want Foreign address to display IP directly, you can use parameter-N.

We can also use parameter-I to view the use of network interfaces:

$ Netstat-ai name    mtu     network       &  nbsp address              Ipkts Ierrs      opkts oerrs    Coll dc0     1500         00:80:c8:f6:b2:66 68890922 15997 8370716    1256 60296                             33:33:c0:f6:78:e9 dc0     1500    fe80:1::280 fe80:1::281:c8ff:           0      -   
      0      -      -                           ff02:1::2:c1f7:78e9 (refs:1)                       
     ff02:1::1            (refs:1)                            ff02:1::1:ffe7:b266 (refs:1) lp0*    1500                                            0       0         0        0       0 lo0     16384                                      34050        0     34050       0        0

Let's briefly explain the meaning of each field: Name: Device names. MTU: The largest transfer unit (units). Network: The network or destination host provided by this interface. Address: The addresses of the interfaces. Ipkts: Represents the Received packet. Ierrs: Indicates the number of packets received but broken. Opkts: Represents a sent packet. Oerrs: A packet that is sent out but broken. Coll: The number of collisions (collision) that occur. When the network load is large, when the packet is sent out, it is easy to collide, the system will wait for some time to send out the packet again when the collision occurs. The more collision times, the worse the online quality.

23.5.6 Sockstat

Lists the open sockets.

$ sockstat user       command     PID    FD PROTO& nbsp;   local address    FOREIGN address root       telnetd 52897     0 tcp4     192.168.0.1:23 192.168.0.2:1969 root         sshd      34063     4 tcp4      *:22             *:* nobody     httpd     11670    tcp4     *:443              *:* nobody     httpd     11670    tcp4     *:80              *:* root       Sendmail    117     4 tcp4     *:25              *:* root       sendmail     117     5 tcp4     *:587      & nbsp;     *:* root       inetd        109     4 tcp4     *:21               *:* user       command      pid     FD proto    Address mysql      mysqld        170      6 Stream/tmp/mysql.sock root        sendmail     117       3 dgram    syslogd[100]:3 root       syslogd    &  nbsp 100      3 dgram   /var/run/log

Each field represents the following meaning: User: Which user opens the socket. Command: Which command to pass through. PID: What is the process ID for this directive? Df:socket's file descriptor number. PROTO: Which kind of agreement. Local address: Native addresses and Port (Internet sockets only). FOREIGN Address: The source and port (Internet sockets only). Address:socket open file or Target program (UNIX sockets only).

23.5.7 Mail

Mail handlers. Old UNIX mail handlers that can be difficult to use for unfamiliar people. But this is a program that happens in every UNIX system, and sometimes we have to use it in the absence of alternatives, at least knowing how to use it to send and receive letters.

Let's say we want to send the letter to root of this machine:

$ mail Root

If we want to send a letter to a non-native user, the recipient format you can use is as follows: user@cc.ncu.edu.tw user@/[140.115.1.13/]

After the mail is executed, the program will ask us to enter the main message, and then we can start typing. When you have finished editing this article, you can press Ctrl+d to send the letter out, or press CTRL + C to cancel it two times.

We can also specify the theme by adding the parameter-S "subject" When executing mail:

$ mail-s "Hi, my Friend" jack@mymail.com

If we want to send the contents of a text file as this article, for example, we can edit a text file Content.txt, and then use the following methods:

$ mail-s "Hi, my Friend" Jack@mymail.com < Content.txt

Having said the letter, let's find out how to receive it. We can mail to receive the letter, if it is root can also use Mail-u user to receive user user's letter.

$ mail
"/var/mail/root": Messages unread
>u  1 jack  Fri Feb  42/690  "Hi friend"
 U  2 jack  Fri Feb 03:02  74/2620  "You Tomorrow"
 u  3 mary@abc.com Sat Feb 03:06 570/33527 "don ' t Forget"
&

The final appearance of the & for the Mail Program command column prompt symbol, at the beginning of the first letter has a symbol ">" represents the current role of the letter. We can enter the mail number directly to read the letter. Alternatively, we can enter the following instructions:

Instructions Description
H List all letters.
R Reply to the current role of the letter.
N Read the next letter.
P Read the previous letter.
Pre [mail number] Keep the letter numbered mail number in the mailbox of the system (/var/mail/). Program mail for the letters that have been read, the preset will move it to the mbox in the user's home directory. If we still want to use POP3 to receive the letter later, we must use the pre to keep the letter in the system's Mail directory.
D Deletes a letter in action.
Z Displays a list of next-page letters.
Q Leave Mail.

23.5.8 telnnet

Use terminals to remotely log on to a host on the network. For example:

$ telnet bbs.mgt.ncu.edu.tw

If you want to be able to enter Chinese in Telnet, you must add a parameter-8:

$ telnet-8 bbs.mgt.ncu.edu.tw

23.5.9 SSH

Using Telnet without data encryption, it is easy to unknowingly disclose information. If you want to log in to a host that provides SSH login, it is best to use SSH.

Usage:

SSH username@hostname
ssh hostname

For example:

$ ssh mary@140.115.77.11
$ ssh jack@mydomain.com
$ ssh mydomain.com

Only play hostname without the user name, the login name will be your current user name.

If the host you are online on is the first time that you get online, hit "Yes" three words:

The authenticity of host ' 140.115.77.11 ' can ' t be established.
RSA key fingerprint is 13:93:8a:61:31:df:41:3f:7a:0a:77:ad:7e:49:e7:3f.
Are you sure your want to continue connecting (yes/no)? Yes

23.5.10 FTP

File transfer program. If the host you want to log in allows you to login, we use the parameter-A to come from the dynamic login.

$ ftp-a freebsd.csie.nctu.edu.tw

When you enter FTP, the prompt column for the command appears. We can enter the following instructions:

Instructions Description
Help or? Displays the instructions that you can use.
Ls Lists the files for the remote directory.
Pwd Displays the remote location of the directory.
CD dir Go to the Remote dir directory.
Get file Retrieve the file file remotely from the remote.
Put file Upload the file file on the local side to the remote machine.
Acsii Use text mode to transfer files.
Binary Transfer files using binary mode.
Bye End FTP.
Mget *.tgz Retrieve all the remote files named *.tgz.
Mput *.tgz Upload all the local *.tgz files.
!ls Displays the files in the local directory.
Lpwd or!pwd Displays the local directory.
lcd [dir] Toggles the local directory.

23.5.11 nslookup

Network host name query. If we want to query the IP of www.freebsd.org, the simplest use is:

$ nslookup www.freebsd.org

We can also add the DNS host to query after the above instructions:

$ nslookup www.freebsd.org dns.hinet.net

We can also use IP to access the reverse search:

$ nslookup 216.136.204.21

23.5.12 Dig

is another powerful host name query tool. The simple usage is as follows:

$ dig-x 216.136.204.21
$ dig www.freebsd.org

23.5.13 tcpdump

Displays or records network packets. If you want to use tcpdump, you must have Berkeley packet filter in the core, and have/dev/bpf*. If not, please add the following line to the core settings and edit the core again:

Pseudo-device BPF

After the tcpdump is executed, it opens the promiscuous mode of the specified interface (the interface must be supported to be useful). The so-called promiscuous mode (clutter) refers to whether or not the machine-related packets are received, to achieve this effect, must be supported by BPF.

We can use tcpdump to observe packets that arrive at a certain network interface. For example, we would like to monitor the packet of interface vr0:

# tcpdump-i Vr0

If you want to end directly press CTRL + C. If you limit the number of packets, you can use the parameter-C. We can also use parameter-W to save the captured packet as a file, where we save the file as a dump:

# tcpdump-c 20-i vr0-w Dump

The stored packet data can be read using parameter-r:

# Tcpdump-r Dump

In order to control tcpdump can dump the packets we want, we can also add some expression at the end of the instruction to control the record of the packet. Please man tcpdump about the use of expression.

Also introduce a useful analysis tool tcpshow, we can use ports to install.

# cd/usr/ports/net/tcpshow
# make install clean

You can then use Tcpshow to analyze the contents of the package we have stored:

# Tcpshow <dump | More
---------------------------------------------------------------
Packet 8 time
:  04:53:10.938750 (0.011744)
LINK:  00:80:2d:bb:65:38-> 00:50:aa:00:dc:dd type=ip  IP:  tw    -> 189 hlen=20 tos=00 dgramlen=44 id=4353 mf/df=0/1 frag=0 ttl=52
 TCP:  Port http-> 2451 seq=3298970558 ack=2899053999  Hlen=24 (data=0) uaprsf=010010 wnd=65535 cksum=8549 urg=0
data:
----------------------------------------- ----------------------

Let's briefly explain the contents of this package. The first part is time.

The second line is LINK, which shows the network card number of the source-> destination, and through TYPE=IP, we know that this is a Ethernet_II frame.

The third part of IP,TW-> 189 is the address of the source and destination. Hlen is the header length size of bytes, and the entire IP envelope (Dgramlen) is the size of bytes.

The fourth part is TCP, the source is port is HTTP (default is 80), and the port of destination is 2451. Next is the sequence number and acknowledgement numbers of the TCP packets. The TCP header length is 24, plus the IP header 20 length is just 44, and, like the length of the Dgramlen, the packet should be undamaged.

Finally, the packet does not contain any other data.

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.