How to read netstat ports? - port

I did the netstat -tulpn | grep listen and had the next results:
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 14901/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1011/exim4
tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 826/ang
tcp6 0 0 :::80 :::* LISTEN 655/apache2
tcp6 0 0 :::22 :::* LISTEN 14901/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1011/exim4
tcp6 0 0 :::443 :::* LISTEN 655/apache2
How can you close a port?
Does this configuration have any security issue?

The 1st part of the question - How to close the port ?
You can stop the service listed in the last column, or kill it. Stopping the service makes sure it wont start again on its own. Killing the service means some other process like upstart might start it up again.
The 2nd part of the question - Does this have a security issue ?
I would say yes, unless you have some firewall and access control mechanism in place. The reason is that the ssh service is listening for connections from any source. Ideally, you would restrict this on the firewall (or in the ssh config) and only allow known sources to connect. If you want to go one step further, make ssh listen on another port than the default port (22) so that you can avoid being seen by the most basic/common scanners. I only mention ssh as an example. You will need to review this periodically for any more software/services you deploy on that machine.

Related

check_mk : I can't access to my monitoring server after install

I just installed a check_mk server, I've done this on other missions, but first time failed after creating a site. I checked with netstat and I have this:
Proto Recv-Q Send-Q Adresse locale Adresse distante
Etat PID/Program name tcp 0 0 127.0.0.1:5000
0.0.0.0:* LISTEN 14925/httpd tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:22 0.0.0.0:*
LISTEN 962/sshd tcp 0 0 127.0.0.1:25
0.0.0.0:* LISTEN 1318/master tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::*
LISTEN 962/sshd tcp6 0 0 ::1:25 :::*
LISTEN 1318/master
telnet on port 80 hangs, ping works, If you have experienced this or suggests are welcome.
Regards,
Hassane
Never mind, I found the solution, for my cas it was the local firewall which was blocking. Disabling it make all works.
Regards,
Hassane

docker: gitlab + traefik & port 22

I need to set up Gitlb behind Traefik.
Everything works except authentication to the app via command line - I don't know how to expose port 22 via traefik.
Any idea how to set it up? How to expose port 22 of a docker container (via traefik)?
I changed the default port from 22 to 10022.
I'm getting via netstat -tulpn
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:22 0.0.0.0:* LISTEN 1132/sshd
tcp 0 0 0.0.0.0:5355 0.0.0.0:* LISTEN 1126/systemd-resolv
tcp6 0 0 :::22 :::* LISTEN 1132/sshd
tcp6 0 0 :::443 :::* LISTEN 1590/docker-proxy
tcp6 0 0 :::10022 :::* LISTEN 1440/docker-proxy
tcp6 0 0 :::5355 :::* LISTEN 1126/systemd-resolv
tcp6 0 0 :::80 :::* LISTEN 1602/docker-proxy
tcp6 0 0 :::8080 :::* LISTEN 1578/docker-proxy
udp 0 0 127.0.0.53:53 0.0.0.0:* 1126/systemd-resolv
udp 0 0 0.0.0.0:68 0.0.0.0:* 864/dhclient
udp 0 0 0.0.0.0:5355 0.0.0.0:* 1126/systemd-resolv
udp6 0 0 :::5355 :::* 1126/systemd-resolv
I don't understand why 10022 is connected to docker-proxy.
When I try:
git push --set-upstream origin master
ssh: connect to host git.myserver.com port 10022: Connection refused
fatal: Could not read from remote repository.
Thank you very much
Traefik is an HTTP reverse proxy, and ssh is not an HTTP protocol. So you'll need to simply publish the container's ssh port on an unused port on the host.
As BMitch said, traefik won't handle TCP traffic if it is not HTTP. (SSH is not HTTP).
See this discussion: https://github.com/containous/traefik/issues/10
I recommend you to configure your networking stuff in order to route the traffic of :22 directly to the container.

How to setup Restund Turn Server with IPv6

I am using Restund for WebRTC. My Restund server currently works with IPv4. I am attempting to update my Restund server to work with both IPv4 and IPv6. I am having some troubles and could use some help.
My dilemma is that my Restund turn server no longer works with Cell Service on iOS Devices since the 10.2 update (When using T-Mobile and Sprint. Note: Verizon is still working). As I understand it, these carriers are now only communicating on IPv6. Other carriers have announced they will be switching soon.
One thing I have noticed is the need to use the "Local" IPv4 address from my eth0 network device as listed in ifconfig. Because of this, I also added the [::1] entries in case the IPv6 cases would require it. I also added the full IPv6 Address. So there are 3 entries for udp_listen, tcp_listen, and tls_listen.
In my example below, I've changed the real addresses to be example addresses.
I've included my /etc/restund.conf file below.
daemon yes
debug no
realm HOST
syncinterval 600
udp_listen 192.168.1.100:3478
udp_listen [::1]:3478
udp_listen [AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA]:3478
udp_sockbuf_size 524288
tcp_listen 192.168.1.100:3478
tcp_listen [::1]:3478
tcp_listen [AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA]:3478
tls_listen 192.168.1.100:3479,/etc/cert.pem
tls_listen [::1]:3479,/etc/cert.pem
tls_listen [AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA]:3479,/etc/cert.pem
# modules
module_path /usr/local/lib/restund/modules
module stat.so
module binding.so
module auth.so
module turn.so
module syslog.so
module status.so
# auth
auth_nonce_expiry 3600
auth_shared_expiry 86400
# share this with your prosody server
auth_shared yoursecretthing
#auth_shared_rollover incaseyouneedtodokeyrollover
# turn
turn_max_allocations 512
turn_max_lifetime 600
turn_relay_addr 192.168.1.100
#turn_relay_addr6 ::1
turn_relay_addr6 AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA
turn_relay_addr6 ::1
# syslog
syslog_facility 24
# status
# 2/2/2017 Apparently only the first status is used, the second one is ignored.
# I verified this by going to:
# http://[AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA]:8080
# http://PUBLIC_IPV4_ADDR:8080/
# Only one would work at a time.
# So I commented the IPv6 Addresses.
status_udp_addr 192.168.1.100
#status_udp_addr AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA
status_udp_port 33000
status_http_addr 192.168.1.100
#status_http_addr AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA
status_http_port 8080
After verifying Restund ran without errors, I verified that the appropriate TCP/UDP ports were now being listened to using netstat -nlp.
One concern I found in the netstat results, was the full IPv6 address only shows 4 of the 8 sets (AAAA:AAAA:AAAA:AAAA instead of AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA). I'm wondering if this is something I should be concerned about.
netstat -nlp
IPv4 && IPv6 [Full Address and ::1]
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.1.100:8080 0.0.0.0:* LISTEN 11442/restund
tcp 0 0 192.168.1.100:3478 0.0.0.0:* LISTEN 11442/restund
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1321/sshd
tcp 0 0 192.168.1.100:3479 0.0.0.0:* LISTEN 11442/restund
tcp6 0 0 AAAA:AAAA:AAAA:AAAA:3478 :::* LISTEN 11442/restund
tcp6 0 0 ::1:3478 :::* LISTEN 11442/restund
tcp6 0 0 :::22 :::* LISTEN 1321/sshd
tcp6 0 0 AAAA:AAAA:AAAA:AAAA:3479 :::* LISTEN 11442/restund
tcp6 0 0 ::1:3479 :::* LISTEN 11442/restund
udp 0 0 192.168.1.100:33000 0.0.0.0:* 11442/restund
udp 0 0 192.168.1.100:3478 0.0.0.0:* 11442/restund
udp 0 0 0.0.0.0:68 0.0.0.0:* 927/dhclient
udp6 0 0 AAAA:AAAA:AAAA:AAAA:3478 :::* 11442/restund
udp6 0 0 ::1:3478 :::* 11442/restund
After all of these IPv6 additions to my /etc/restund.conf file, I am still unable to communicate via IPv6. Thanks in advance for any input!
This won't resolve your IPv6 issue, but it should make your code work for now.
On January 27 T-Mobile Released a Carrier Update for iOS 10.2.1 Carrier 27.2:
https://support.t-mobile.com/docs/DOC-32574
Try Updating your Carrier Settings and it may fix the T-Mobile Issue.
From the Home screen, tap Settings.
Tap General
Tap About and then review the Carrier Update Field.
It should prompt you to update at this point if you haven't already. See if that resolves your problem with T-Mobile. They added an update that "Adds dual stack to improve app compatibility issues with iOS 10.2".

Fixed issue with connecting to docker but don't know why the fix worked

I had trouble connecting to my hbase docker via hbase shell from my local machine so I went into the container and did netstat -atp tcp | grep -i "listen"
tcp 0 0 03de42531368:16000 :::* LISTEN 184/java
tcp 0 0 :::9090 :::* LISTEN 507/java
tcp 0 0 :::2181 :::* LISTEN 12/java
tcp 0 0 :::9095 :::* LISTEN 507/java
tcp 0 0 03de42531368:16201 :::* LISTEN 276/java
tcp 0 0 :::16010 :::* LISTEN 184/java
tcp 0 0 :::16301 :::* LISTEN 276/java
tcp 0 0 :::http-alt :::* LISTEN 373/java
tcp 0 0 :::8085 :::* LISTEN 373/java
I saw my container in the response. Then I updated /etc/hosts with 03de42531368 pointing to 127.0.0.1. Afterwards, I was able to connect to my hbase docker.
That fixed the issue, however I had no idea why I saw my container id in the netstat response and had to add 03de42531368 to /etc/hosts.
Can anyone explain?

Docker and netstat: netstat is not showing ports, exposed by docker containers

I expose docker ports of my contaners to the host machine with something like
docker run -p 80:80 ...
then I try to display all listening ports for debugging purposes with netstat e.g.:
netstat -at
Strange thing is that netstat won't display my docker containers with exposed ports, although they are listening and reply to the browser.
How do I make netstat display those exposed ports?
UPDATE:
I'm running this on Debian 8 Jessie. Here's what I do:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9dfa08bab50d workflows-nginx "/bin/sh -c '/usr/sbi" 2 hours ago Up 2 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp workflows-nginx
d0b0c3f90f13 workflows-django "/bin/sh -c 'python /" 7 hours ago Up 3 hours 0.0.0.0:8000->8000/tcp workflows-django
99a857c92533 workflows-db "/docker-entrypoint.s" 7 hours ago Up 3 hours 5432/tcp workflows-db
Here docker reports that container ports are forwarded to the host. Moreover, if I stop workflows-nginx container, it stops answering to the browser by http (port 80). If I start it again, it starts responding again.
Here is the output of sudo netstat -at | less:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 *:15672 *:* LISTEN
tcp 0 0 *:postgresql *:* LISTEN
tcp 0 0 localhost:smtp *:* LISTEN
tcp 0 0 *:25672 *:* LISTEN
tcp 0 0 *:48142 *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 *:epmd *:* LISTEN
tcp 0 0 bob-acer:34866 104.16.33.249:http ESTABLISHED
tcp 0 0 bob-acer:42380 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:42543 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:42525 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:44076 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:42944 stackoverflow.com:https ESTABLISHED
tcp 0 0 localhost:epmd localhost:50831 ESTABLISHED
tcp 0 0 bob-acer:42655 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:42384 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:44626 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:42390 stackoverflow.com:https ESTABLISHED
tcp 0 0 localhost:50831 localhost:epmd ESTABLISHED
tcp 0 0 bob-acer:48301 c2.52.c0ad.ip4.st:https ESTABLISHED
tcp 0 0 bob-acer:42151 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:42205 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:42539 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:44737 stackoverflow.com:https ESTABLISHED
tcp 0 0 bob-acer:39648 77.94.164.251:https ESTABLISHED
tcp6 0 0 [::]:ssh [::]:* LISTEN
tcp6 0 0 localhost:ipp [::]:* LISTEN
tcp6 0 0 [::]:postgresql [::]:* LISTEN
tcp6 0 0 localhost:smtp [::]:* LISTEN
tcp6 0 0 [::]:44794 [::]:* LISTEN
tcp6 0 0 [::]:8000 [::]:* LISTEN
tcp6 0 0 [::]:amqp [::]:* LISTEN
tcp6 0 0 [::]:sunrpc [::]:* LISTEN
tcp6 1 0 localhost:58497 localhost:ipp CLOSE_WAIT
As you can see, neither port 80, nor port 443 are reported. Port 8000 of workflows-django for some reason is opened on IPv6 interface. Moreover, I forgot to disable postgres on host machine and still they don't clash with postgres container workflows-db.
Everything is running on my local notebook, so I guess there can't be any confusion with the host.
My docker version is:
docker --version
Docker version 1.10.3, build 20f81dd
ANSWER: This is related to docker EXPOSE parameter. If you write this line in your dockerfile and run the container with -p, the port will be visible in netstat. If you use -p but don't write EXPOSE, your port won't be listed by netstat.
It's never too late to answer a question.
Using netstat -tln, not netstat -at.
It's very simple to answer, if you notify the --numeric option for netstat. By using this option, netstat will print address with numbers instead of meaningful string. Then you can grep them as you mentioned. Following shows how it works.
[root#A01-R26-I52-155-3002023 ~]# netstat -tl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost.localdom:smux 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdo:18121 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdo:18122 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdo:18123 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdo:18124 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdo:18125 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:sunrpc 0.0.0.0:* LISTEN
tcp 0 0 localhost.localdo:18928 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:20080 0.0.0.0:* LISTEN
tcp 0 0 A01-R26-:univ-appserver 0.0.0.0:* LISTEN
tcp 0 0 A01-R26-:univ-appserver 0.0.0.0:* LISTEN
tcp 0 0 localhost.:search-agent 0.0.0.0:* LISTEN
tcp 0 0 localhost:mosaicsyssvc1 0.0.0.0:* LISTEN
tcp 0 0 A01-R26-I52-155-300:ssh 0.0.0.0:* LISTEN
tcp6 0 0 [::]:37611 [::]:* LISTEN
tcp6 0 0 [::]:sunrpc [::]:* LISTEN
tcp6 0 0 [::]:microsan [::]:* LISTEN
tcp6 0 0 [::]:commtact-http [::]:* LISTEN
[root#A01-R26-I52-155-3002023 ~]# netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:18121 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:18122 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:18123 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:18124 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:18125 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:18928 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:20080 0.0.0.0:* LISTEN
tcp 0 0 10.217.52.155:1233 0.0.0.0:* LISTEN
tcp 0 0 10.218.52.155:1233 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:1234 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:1235 0.0.0.0:* LISTEN
tcp 0 0 10.217.52.155:22 0.0.0.0:* LISTEN
tcp6 0 0 :::37611 :::* LISTEN
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::20001 :::* LISTEN
tcp6 0 0 :::20002 :::* LISTEN
netstat should display the exposed ports. Here is an example
anovil#anovil-Latitude-E6440:docker$ sudo netstat -at|grep 3030
anovil#anovil-Latitude-E6440:docker$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
anovil#anovil-Latitude-E6440:docker$ docker run -d -p 3030:80 httpd:2.4
4310ac5fbdbc7314ab4d23e34099a710a3a8790dcf2c6d0a84202c1de5c9fd30
anovil#anovil-Latitude-E6440:docker$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4310ac5fbdbc httpd:2.4 "httpd-foreground" 3 minutes ago Up 3 minutes 0.0.0.0:3030->80/tcp hungry_fermat
anovil#anovil-Latitude-E6440:docker$ sudo netstat -at|grep 3030
tcp6 0 0 [::]:3030 [::]:* LISTEN
anovil#anovil-Latitude-E6440:docker$ sudo netstat -tulpn|grep 3030
tcp6 0 0 :::3030 :::* LISTEN 10294/docker-proxy
anovil#anovil-Latitude-E6440:docker$
Some basic things you need to verify yourself:
Are you running netstat with elevated privileges? Somethings might miss out when you are non-root
Is your docker container running on the same host as you expect? Check with docker ps
Does docker ps list the port forwarding? Like from the above, you should be able to see something like this 0.0.0.0:3030->80/tcp
Also note that, the docker-proxy is the one running on the host.
All commands above assumes that you run on linux.
This was tested with ubuntu 15.10
If you still feel you are missing the forwarding, then please post back your Operating System, docker version etc.
Thanks,
This code will show you the opened ports with the pids inside the container:
container_name=some_container_name
c_pid=`docker container inspect -f "{{.State.Pid}}" ${container_name}`
nsenter -t ${c_pid} -n netstat -anp
They are listed, just not in the way you might expect. If you're looking for an ipv4 listen port you won't see it (unless I believe if you're using both the EXPOSE and publish (-p) mechanisms in tandem), but what you will see is a docker proxy on ipv6, e.g. for a MySQL container:
netstat -tlpn4
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::3306 :::* LISTEN 9608/docker-proxy

Resources