View Network Ports in Linux

Source: Internet
Author: User

View Network Ports in Linux

Briefly summarize the results of learning Linux in the past.

 

Check whether TCP 22 is enabled. 1. List all ports: [root @ Demon proc] # netstat-ntlpActive Internet connections (only servers) Proto...

1. Check whether port TCP 22 is enabled.

1. List all ports:

[Root @ Demon proc] # netstat-ntlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

Tcp 0 0 0.0.0.0: 111 0.0.0.0: * LISTEN 1634/rpcbind

Tcp 0 0 0.0.0.0: 8080 0.0.0.0: * LISTEN 13888/nginx

Tcp 0 0 0.0.0.0: 22 0.0.0.0: * LISTEN 1960/sshd

Tcp 0 0 127.0.0.1: 631 0.0.0.0: * LISTEN 1823/cupsd

Tcp 0 0 127.0.0.1: 25 0.0.0.0: * LISTEN 2359/master

Tcp 0 0 0.0.0.0: 52771 0.0.0.0: * LISTEN 1779/rpc. statd

Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN 2263/mysqld

Tcp 0 0: 111: * LISTEN 1634/rpcbind

Tcp 0 0: 22: * LISTEN 1960/sshd

Tcp 0 0: 1: 631: * LISTEN 1823/cupsd

Tcp 0 0: 1: 25: * LISTEN 2359/master

Tcp 0 0: 52072: * LISTEN 1779/rpc. statd

2. There are two methods to view the TCP 22 Port:

# Method 1

[Root @ Demon proc] # netstat-ntlp | grep 22

Tcp 0 0 0.0.0.0: 22 0.0.0.0: * LISTEN 1960/sshd

Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN 2263/mysqld

Tcp 0 0: 22: * LISTEN 1960/sshd

# Method 2

[Root @ Demon proc] # lsof-I tcp: 22

Command pid user fd type device size/OFF NODE NAME

Sshd 1960 root 3u IPv4 14435 0t0 TCP *: ssh (LISTEN)

Sshd 1960 root 4u IPv6 14441 0t0 TCP *: ssh (LISTEN)

Ii. Network Configuration

1. static IP settings

# First, open the NIC configuration file:

[Root @ Demon proc] # vim/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE = eth0 # specify the DEVICE name

UUID = 1bc2ebe3-0b0c-4a67-89eb-9214a7bd97d0

BOOTPROT = static # Start type (another dynamic is dhcp)

BROADCAST = 192.168.1.222 # BROADCAST address

HWADDR = 00: 06: 5B: FE: DF: 7C # hardware Mac address

IPADDR = 192.168.1.54 # IP Address

NETMASK = 255.255.255.0 # Subnet Mask

NETWORK = 192.168.0.0 # NETWORK address

GATEWAY = 192.168.0.1 # GATEWAY address

ONBOOT = yes # Start or not

TYPE = Ethernet # network TYPE

# Restart an Eni

[Root @ Demon proc] # service network restart

Closing interface eth0: device status: 3 (disconnect) [OK]

Disable the loop interface: [OK]

Pop-up loop interface: [OK]

Pop-up page: eth0: active connection status: Active

Active connection path:/org/freedesktop/NetworkManager/ActiveConnection/12

Status: Activated

Connection activated [OK]

2. Dynamic IP settings

# First, open the NIC configuration file:

[Root @ Demon proc] # vim/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE = eth0 # specify the DEVICE name

UUID = 1bc2ebe3-0b0c-4a67-89eb-9214a7bd97d0

BOOTPROT = dhcp # Start type

BROADCAST = 192.168.1.222 # BROADCAST address

HWADDR = 00: 06: 5B: FE: DF: 7C # hardware Mac address

ONBOOT = yes # Start or not

TYPE = Ethernet # network TYPE

# Restart an Eni

[Root @ Demon proc] # service network restart

Closing interface eth0: device status: 3 (disconnect) [OK]

Disable the loop interface: [OK]

Pop-up loop interface: [OK]

Pop-up page: eth0: active connection status: Active

Active connection path:/org/freedesktop/NetworkManager/ActiveConnection/12

Status: Activated

Connection activated [OK]

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.