Linux server listen port

How to listen new port Ubuntu Server from command line?

But then no output. I am new to Ubuntu, Anyone can help me with it? EDIT : I want to listen new port 3000 same as following port :

2 Answers 2

Ubuntu Server itself will not listen to any port. The application services installed and ran at the server listen to ports. For example, by default:

If you want to get the names of the services that listen at the ports on your system, use netstat by root via sudo in this way:

$ sudo netstat -pna | grep "LISTEN " | grep '\' tcp 0 0 0.0.0.0:6951 0.0.0.0:* LISTEN 8976/aria2c tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1589/mysqld tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 32285/redis-server tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 1279/memcached tcp 0 0 127.0.0.1:8142 0.0.0.0:* LISTEN 1482/nodejs tcp 0 0 127.0.0.1:6800 0.0.0.0:* LISTEN 8976/aria2c tcp 0 0 127.0.0.1:81 0.0.0.0:* LISTEN 3286/docker-proxy tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 1218/systemd-resolv tcp 0 0 127.0.0.1:4822 0.0.0.0:* LISTEN 1445/guacd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 77768/apache2 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1339/sshd: /usr/sbi tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2805/master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 77768/apache2 
  • 127.0.0.1 means the loopback interface (localhost),
  • 0.0.0.0 means all available interfaces (localhost, network adapters, etc.),
  • some services could listen at certain interfaces, i.e. 192.168.1.100 or it could be some IPv6 address.

If there is a firewall and you want to access your services outside you need to allow input/output traffic to the ports they listen.

By using nc -l 3000 the command nc itself will start to listen at port 3000. IMO, this option is designed for test purposes, i.e. you are setup firewall or so.

Let’s say in a terminal you’ve ran:

Then in another terminal you can test does something listen to port 3000 by:

$ nc -vz 0.0.0.0 3000 Connection to 0.0.0.0 3000 port [tcp/*] succeeded! 

Your must design your service (program, script, command) to listen at the desired port 3000 and when this port is not used by some other service, when you start your service it will start to listen to the port.

In other hand if you need something to listen constantly at . 3000 in order to do your tests, the most easiest way, in my opinion, is to create systemd unit. For this purpose:

sudo nano /etc/systemd/system/listen-3000.service 
[Unit] Description=Permanent listen at . 3000 After=network-online.target [Service] User=root ExecStart=/usr/bin/nc -l6 3000 ExecStop=/usr/bin/killall -s KILL nc Restart=always RestartSec=1 [Install] WantedBy=multi-user.target 
sudo systemctl daemon-reload sudo systemctl enable listen-3000.service sudo systemctl start listen-3000.service sudo systemctl status listen-3000.service 
sudo systemctl stop listen-3000.service sudo systemctl disable listen-3000.service 

Источник

Читайте также:  Linux intel graphics driver installer

Check for Listening Ports in Linux

Check Open Ports in Linux

When troubleshooting network connectivity or application-specific issues, one of the first things to check should be what ports are actually in use on your system and which application is listening on a specific port.

This article explains how to use the netstat , ss and lsof commands to find out which services are listening on which ports. The instructions are applicable for all Linux and Unix-based operating systems like macOS.

What is Listening Port

Network port is identified by its number, the associated IP address, and type of the communication protocol, such as TCP or UDP.

Listening port is a network port on which an application or process listens on, acting as a communication endpoint.

Each listening port can be open or closed (filtered) using a firewall. In general terms, an open port is a network port that accepts incoming packets from remote locations.

You can’t have two services listening to the same port on the same IP address.

For example, if you are running an Apache web server that listens on ports 80 and 443 and you try to install Nginx , the later will fail to start because the HTTP and HTTPS ports are already in use.

Check Listening Ports with netstat

netstat is a command-line tool that can provide information about network connections.

To list all TCP or UDP ports that are being listened on, including the services using the ports and the socket status use the following command:

The options used in this command have the following meaning:

  • -t — Show TCP ports.
  • -u — Show UDP ports.
  • -n — Show numerical addresses instead of resolving hosts.
  • -l — Show only listening ports.
  • -p — Show the PID and name of the listener’s process. This information is shown only if you run the command as root or sudo user.

The output will look something like this:

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 445/sshd tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 929/master tcp6 0 0 . 3306 . * LISTEN 534/mysqld tcp6 0 0 . 80 . * LISTEN 515/apache2 tcp6 0 0 . 22 . * LISTEN 445/sshd tcp6 0 0 . 25 . * LISTEN 929/master tcp6 0 0 . 33060 . * LISTEN 534/mysqld udp 0 0 0.0.0.0:68 0.0.0.0:* 966/dhclient 

The important columns in our case are:

  • Proto — The protocol used by the socket.
  • Local Address — The IP Address and port number on which the process listen to.
  • PID/Program name — The PID and the name of the process.

If you want to filter the results, use the grep command . For example, to find what process listens on TCP port 22 you would type:

sudo netstat -tnlp | grep :22 

The output shows that on this machine port 22 is used by the SSH server:

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 445/sshd tcp6 0 0 . 22 . * LISTEN 445/sshd 

If the output is empty it means that nothing is listening on the port.

You can also filter the list based on criteria, for example, PID, protocol, state, and so on.

Читайте также:  Kali linux время установки

netstat is obsolete and replaced with ss and ip , but still it is of the most used commands to check network connections.

Check Listening Ports with ss

ss is the new netstat . It lacks some of the netstat features, but exposes more TCP states and it is slightly faster. The command options are mostly the same, so the transition from netstat to ss is not difficult.

To get a list of all listening ports with ss you would type:

The output is almost the same as the one reported by netstat :

State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=445,fd=3)) LISTEN 0 100 0.0.0.0:25 0.0.0.0:* users:(("master",pid=929,fd=13)) LISTEN 0 128 *:3306 *:* users:(("mysqld",pid=534,fd=30)) LISTEN 0 128 *:80 *:* users:(("apache2",pid=765,fd=4),("apache2",pid=764,fd=4),("apache2",pid=515,fd=4)) LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=445,fd=4)) LISTEN 0 100 [::]:25 [::]:* users:(("master",pid=929,fd=14)) LISTEN 0 70 *:33060 *:* users:(("mysqld",pid=534,fd=33)) 

Check Listening Ports with lsof

lsof is a powerful command-line utility that provides information about files opened by processes.

In Linux, everything is a file. You can think of a socket as a file that writes to the network.

To get a list of all listening TCP ports with lsof type:

sudo lsof -nP -iTCP -sTCP:LISTEN 

The options used are as follows:

  • -n — Do not convert port numbers to port names.
  • -p — Do not resolve hostnames, show numerical addresses.
  • -iTCP -sTCP:LISTEN — Show only network files with TCP state LISTEN.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 445 root 3u IPv4 16434 0t0 TCP *:22 (LISTEN) sshd 445 root 4u IPv6 16445 0t0 TCP *:22 (LISTEN) apache2 515 root 4u IPv6 16590 0t0 TCP *:80 (LISTEN) mysqld 534 mysql 30u IPv6 17636 0t0 TCP *:3306 (LISTEN) mysqld 534 mysql 33u IPv6 19973 0t0 TCP *:33060 (LISTEN) apache2 764 www-data 4u IPv6 16590 0t0 TCP *:80 (LISTEN) apache2 765 www-data 4u IPv6 16590 0t0 TCP *:80 (LISTEN) master 929 root 13u IPv4 19637 0t0 TCP *:25 (LISTEN) master 929 root 14u IPv6 19638 0t0 TCP *:25 (LISTEN) 

Most of the output columns names are self-explanatory:

  • COMMAND , PID , USER — The name, the pid and the user running the program associated with the port.
  • NAME — The port number.

To find what process is listening on a particular port, for example, port 3306 you would use:

sudo lsof -nP -iTCP:3306 -sTCP:LISTEN 

The output shows that MySQL server uses port 3306 :

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 534 mysql 30u IPv6 17636 0t0 TCP *:3306 (LISTEN) 

For more information, visit the lsof man page and read about all other powerful options of this tool.

Conclusion

We have shown you several commands that you can use to check what ports are in use on your system, and how to find what process listens on a specific port.

If you have any questions or remarks, please leave a comment below.

Источник

Linux server listen port

How to install the Varnish cache for faster web page loads on AlmaLinux

Virtual machine concept

Learn to install the Pritunl VPN server on AlmaLinux

20211230-csf-jack.jpg

How to install the CSF firewall on Ubuntu Server

Human Hand Drawing Security Concepts

How to check if your Linux servers are vulnerable to the Log4j flaw with a single command

kanboard-kanban-board-install-tutorial-jackwallen.jpg

How to install the Kanboard kanban platform in your data center

20211103-dockstation-jack.jpg

This is the Docker GUI you’ve been waiting for

20211025-cubic-jack.jpg

Use Cubic to create your own data center-specific Linux image

Most Recent

How to Edit the Linux Hosts File

In this TechRepublic How to Make Tech Work video, Jack Wallen shows how to access and modify the Linux hosts file to control the mapping of hostnames to IP addresses.

Читайте также:  How to edit files in linux terminal

How to Add the Docker Scout Feature to the Docker CLI

In this TechRepublic How to Make Tech Work video, Jack Wallen shows you how to add the Docker Scout feature to the Docker CLI.

How to Stop and Remove All Docker Containers with 2 Simple Commands

In this TechRepublic How to Make Tech Work video, Jack Wallen shows how to stop and remove all Docker containers at once with just two simple commands.

How to reset your Portainer admin password

Forgot your Portainer admin password? Learn how to use a handy tool to help you reset it with a tutorial from Jack Wallen.

The easiest method of installing Docker on Linux

In this TechRepublic How to Make Tech Work video, Jack Wallen shows you how to install Docker on Linux machines.

Scale Docker Swarm services video.

How to scale Docker Swarm services

In this TechRepublic How to Make Tech Work video, Jack Wallen demonstrates how to attach and remove nodes from clusters in Docker Swarm to scale your services up and down as needed.

Tech Impact: Sustainable and Innovative Solutions to Tackle Tech Plastic Waste.

Tech Impact: Sustainable and innovative solutions to tackle tech plastic waste

Join us as we dive deep into how industry giants like Dell, Microsoft and Apple are addressing the issue of plastic waste in the tech sector.

How to compile a C++ program on Linux.

How to compile a C++ program on Linux

In this TechRepublic How to Make Tech Work video, Jack Wallen shows you the step-by-step process of compiling a C++ program on Linux, using Ubuntu Desktop 23.04 for his demo.

TechRepublic Premium

Hiring Kit: Virtual Reality Designer

This hiring kit from TechRepublic Premium contains a job description, sample interview questions and a basic want ad to help you find the best candidates for a virtual reality designer position. From the hiring kit: INTRODUCTION While the concept of virtual and augmented reality applications has been around for decades, the technological ability to render .

Accomplishment Tracker

Having a structured way to keep track of your noteworthy accomplishments will help you be at your best when review time rolls around. It can also help with ideas when you’re feeling stuck trying to revise your resume. That’s where TechRepublic Premium can help with this guide and accompanying worksheet. Add information to the worksheet . Provided By TechRepublic Premium Published: Jul 2023 Modified: Jul 2023 Read More

Hiring Kit: Security Architect

Developing and implementing both preventive security protocols and effective response plans is complicated and requires a security architect with a clear vision. This hiring kit from TechRepublic Premium provides a workable framework you can use to find the best candidate for your organization. From the hiring kit: DETERMINING FACTORS, DESIRABLE PERSONALITY TRAITS AND SKILLSETS Depending .

Branch Office Network Design Considerations

Like a Rubik’s Cube, it is possible to solve the branch networking puzzle with the help of this guide from TechRepublic Premium. From the guide: WHY SO COMPLICATED? When you really stop and think about it, a branch office is really nothing more than an extension of your existing network. If that is true, then .

Источник

Оцените статью
Adblock
detector