服务器地址和端口号是什么怎么看

服务器地址和端口号是什么怎么看?这两个一般要分开来看比较好,接下来我们为您提供了具体的查看方法。

服务器,ip,dns

服务器地址查看方法

方法1#使用ifconfig命令

ifconfig命令一般在/sbin可用。因此,您将需要root或sudo访问权限,以便在许多操作系统上运行。

$ ifconfig

示例输出

eth0      Link encap:Ethernet  HWaddr 00:0C:22:83:79:A3
          inet addr:192.168.10.199  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe89:79b3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3931508 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1333146 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:706273621 (673.5 MiB)  TX bytes:857722605 (817.9 MiB)
          Base address:0x2000 Memory:fd5c0000-fd5e0000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:654 errors:0 dropped:0 overruns:0 frame:0
          TX packets:654 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:90459 (88.3 KiB)  TX bytes:90459 (88.3 KiB)

根据上述输出,此系统在以太网接口eth0上具有IP地址192.168.10.199。 您还可以使用以下命令查看特定的接口详细信息

$ ifconfig eth0

此外,您可以指定完整的命令路径,以防命令在PATH环境下不可用。

$ /sbin/ifconfig eth0

方法2#使用ip命令

ip命令一般在/ bin目录下可用,但一些Linux os保存在/ sbin目录下。使用以下命令使用ip命令获取ip地址。

# ip addr show

示例输出:

1: lo:  mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0C:22:83:79:A3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.199/24 brd 192.168.1.255 scope global eth0 
    inet6 fe80::20c:29ff:fe89:79b3/64 scope link
       valid_lft forever preferred_lft forever
3: eth1:  mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:89:79:bd brd ff:ff:ff:ff:ff:ff
4: sit0:  mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0

根据上述输出,此系统在以太网接口eth0上具有IP地址192.168.10.199。接口eth1未配置任何IP地址。 您还可以使用以下命令查看特定的itnerface详细信息

# ip addr show eth0

端口号查看方法

以下的命令较多,详细的用法不必深究,先记住固定用法,后期遇到了再细讲。

方法 1:使用 ss 命令

ss 一般用于转储套接字统计信息,类似于 netstat 输出的信息,但它显示了更多的 TCP 信息和状态信息。它还可以显示所有类型的套接字统计信息,包括 PACKET、TCP、UDP、DCCP、RAW、Unix 域等。

[root@localhost ~]#  ss -tnlp | grep dmserver
State      Recv-Q Send-Q          Local Address:Port                         Peer Address:Port              
LISTEN     0      5                           *:5900                                    *:*                   users:          
LISTEN     0      128         :::5236                    :::*                   users:(("dmserver",pid=7060,fd=4))
[root@localhost ~]# 

方法 2:使用 netstat 命令

netstat 能够显示网络连接、路由表、接口统计信息、伪装连接以及多播成员。既然已经会用ss的高级命令了,就忘记它吧。

[root@localhost ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp6       0      0 :::4236                 :::*                    LISTEN      7059/dmap               
tcp6       0      0 :::5236                 :::*                    LISTEN      7060/dmserver       
tcp6       0      0 :::22                   :::*                    LISTEN      6831/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      6832/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      7225/master         
[root@localhost ~]# 

方法 3:使用 fuser 命令

fuser 工具会将本地系统上打开了文件的进程的进程 ID 显示在标准输出中,一般通过端口去查看对应的进程和和用户。

[root@localhost ~]# fuser -v  5236/tcp
                     用户     进程号 权限   命令
5236/tcp:            dmdba      7060 F.... dmserver

方法 4:使用 nmap 命令

nmap(“Network Mapper”)是一款用于网络检测和安全审计的开源工具。它最初用于对大型网络进行快速扫描,但它对于单个主机的扫描也有很好的表现。

nmap 使用原始 IP 数据包来确定网络上可用的主机,这些主机的服务(包括应用程序名称和版本)、主机运行的操作系统(包括操作系统版本等信息)、正在使用的数据包过滤器或防火墙的类型,以及很多其它信息。

[root@localhost ~]# nmap -sV -p 5236 localhost

Starting Nmap 6.40 ( http://nmap.org ) at 2021-01-01 00:23 CST
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00031s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT     STATE SERVICE    VERSION
5236/tcp open  tcpwrapped

Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 10.91 seconds

可以看出,对于普通用户来说,该命令似乎并不好用,也看得不大懂,还需要注意的是该命令一般不会默认安装,需要额外安装。

方法 5:使用 systemctl 命令

systemctl 是 systemd 系统的控制管理器和服务管理器,通过systemctl可以查看服务的具体运行信息,包括PID、是否自启、启动命令等。很遗憾,通过该命令只能查看到对应的PID进程号,如果要查看对应的端口号,可以通过本文中其他端口号、进程号查看方法进行互查。

[root@localhost ~]# systemctl status DmServiceDMSERVER.service 
● DmServiceDMSERVER.service - DM database instance service
   Loaded: loaded (/usr/lib/systemd/system/DmServiceDMSERVER.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2021-03-22 16:33:05 CST; 15h ago
  Process: 6837 ExecStart=/soft/dmdb/bin/DmServiceDMSERVER start (code=exited, status=0/SUCCESS)
 Main PID: 7060 (dmserver)
    Tasks: 54
   CGroup: /system.slice/DmServiceDMSERVER.service
           └─7060 /soft/dmdb/bin/dmserver /soft/dmdb/data/DAMENG/dm.ini -noconsole

3月 22 16:32:48 localhost.localdomain systemd[1]: Starting DM database instance service...
3月 22 16:33:05 localhost.localdomain DmServiceDMSERVER[6837]: [39B blob data]
3月 22 16:33:05 localhost.localdomain systemd[1]: Started DM database instance service.
[root@localhost ~]# 

方法 6:使用 lsof 命令

lsof 能够列出打开的文件,并列出系统上被进程打开的文件的相关信息。

[root@localhost ~]# lsof -i:5236
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dmserver 7060 dmdba    4u  IPv6  46668      0t0  TCP *:padl2sim (LISTEN)

总体来说,进程号和端口号查看的办法虽然很多,但在实际工作中,我们只需要掌握一种自己认为最好用的命令就可以了。后期会根据情况对相关命令进行复盘,详细介绍其用法。

服务器地址和端口号是什么怎么看

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注