What localhost exactly domains name resolution to ip? - spring

My timing database influx sets the listening port 8088 to address 127.0.0.1, and the spring boot listens to the same port 8088 to any addresses, as shown below.
~ lsof -nP -i:8088
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
influxd 420 zyx 3u IPv4 0xf4af94bc970b15e9 0t0 TCP 127.0.0.1:8088 (LISTEN)
java 34029 zyx 171u IPv6 0xf4af94bc9a0d12e9 0t0 TCP *:8088 (LISTEN)
When I try to access spring boot restful using url localhost:8088/api, I get the right result. But when I use url 127.0.0.1:8088/api, I get error java.net.SocketException: Connection reset.I guess it is caused by mapping to influd instead of spring boot.
But why localhost can get the right result? As far as I konw, localhost will resolve to 127.0.0.1.
I run my program on Mac 2019.
~ nslookup localhost
Server: 192.168.15.1
Address: 192.168.15.1#53
Name: localhost.cluster.peidan.me
Address: 127.0.0.1

Related

Accessing tcp port 8080 externally on macos mojave

I am trying to access a listening tcp socket on my macbook from any external client on the same wi-fi lan.
This works for specific ports, eg. 8000, but not other ports, eg. 8080, 8081, 8082
How can I open up or access the 8080 tcp port externally?
Working steps on port 8000
Server
$ nc -lv 8000
Client
$ nc -z 192.168.101.98 8000
Connection to 192.168.101.98 port 8000 [tcp/irdmi] succeeded!
Non-working steps on port 8080
Server
$ nc -lv 8080
Client
$ nc -z 192.168.101.98 8080
(The command just hangs)
Diagnostics
$ lsof -P -i TCP:8000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nc 75782 ... 3u IPv4 0x5be3e11e5a732339 0t0 TCP *:8000 (LISTEN)
$ lsof -P -i TCP:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nc 75952 ... 3u IPv4 0x5be3e11e581e2fb9 0t0 TCP *:8080 (LISTEN)
$ sudo pfctl -s all | grep Status
No ALTQ support in kernel
ALTQ related functions disabled
Status: Disabled Debug: Urgent
I am running macOS Mojave 10.14.1 (same behavior on 10.14 as well).
Update
I changed nothing, everything suddenly works. I am very curious what made the difference. Will close the question, if everything keeps working.
Solution
I had the Endpoint Security VPN client installed. This activates a firewall at all times blocking some ports. Even when not connecting to a vpn server.
By shutting down the client daemon, i can access all ports again.
Steps to shutdown daemon
From: https://gist.github.com/phoob/671e65332c86682d5674
kill client and run commands to stop daemon:
sudo launchctl unload /Library/LaunchDaemons/com.checkpoint.epc.service.plist
sudo kextunload /Library/Extensions/cpfw.kext

Cannot connect to jetty 9

Why can I not successfully connect to jetty?
I have the latest version of jetty 9.x running. I have the jetty_base folder setup and when I drop war files into the folder I see them get expanded into the /tmp folder.
lsof -i :8080
java 26488 jetty 85u IPv6 400595 0t0 TCPlocalhost.localdomain:webcache (LISTEN)
curl 'http://localhost:8080' curl: (7) Failed connect to
localhost:8080; Connection refused
curl http://127.0.0.1:8080 curl: (7) Failed connect to 127.0.0.1:8080;
Connection refused
From the below output of lsof -i:8080
java 26488 jetty 85u IPv6 400595 0t0
TCPlocalhost.localdomain:webcache (LISTEN)
It seems jetty is using ipv6 rather ipv4.
For ipv6, use ::1 as your loopback address. For ipv4, it is 127.0.0.1.
Changes you can make for localhost to work :
If you wish to set localhost to work for both ipv6 and ipv4 you can make below changes to /etc/hosts file.
127.0.0.1 localhost
# ... and below
::1 localhost ipv6-localhost ipv6-loopback
As always, you can test the connectivity using ping6 ::1 for an ipv6 ip and ping 127.0.0.1 for ipv4.
Give a try!

Access jboss 8080 port inside docker container

I'm running jboss5 in centos6.7 docker contrainer.
JBoss running using run.sh -b 0.0.0.0 command
Container running using docker run -i -t -p 8080:8080 my/jboss /bin/bash
This is what I see in container
[root#e44f2bbab31a bin]# netstat -alnt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8083 0.0.0.0:* LISTEN
This is what I see on host
15:04:17:(~)$ sudo docker ps
[sudo] password for c0rp:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e44f2bbab31a my/jboss "/bin/bash" 4 hours ago Up 4 hours 0.0.0.0:8080->8080/tcp thirsty_franklin
When I'm trying to access jboss application from host by localhost:8080 I see ERROR 404: Not Found.
When I'm checking localhost:8080 from inside container using wget I see same error ERROR 404: Not Found.
Everything is ok if I'm using ip address of container. Question is how can I bind host localhost:8080 to container ip_address:8080 ?
localhost is a alias for 127.0.0.1. This address used for loopback. It means what your request will returned to the same machine on Network OSI model layer(through lo0 interface in ifconfig command). But you can get access to your container using request to localhost:
!!!Very-very dirty hack!!! Don't use it. Just for understanding of localhost issue. You can edit hosts file (example for Mac):
sudo nano /private/etc/hosts
You will see something like this:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
Just replace 127.0.0.1 by ip of your container. I'm repeating: it's just for understanding of localhost
You can run NGINX instance on your localhost machine. You can configure it for sending all requests from localhost:8080 to containerIp:8080 (best variant without any configuration with routing)
I found that running
FROM registry.access.redhat.com/jboss-eap-7/eap71-openshift
that I also needed to open the management port, so you (or rather, someone in the future coming across this thread) should try this:
docker run -dit -p 8080:8080 -p 9990:9990 [image name]

Unable to telnet on ec2 even when HTTPS /port 443 is open

Settings of my security group on EC2
TCP
Port(Service) Source Action
22 (SSH) 0.0.0.0/0 Delete
80 (HTTP) 0.0.0.0/0 Delete
443 (HTTPS) 0.0.0.0/0 Delete
Output: When I run the telnet
JP$ telnet passionate4.net
Trying 50.18.159.124...
telnet: connect to address 50.18.159.124: Operation timed out
telnet: Unable to connect to remote host
on ubuntu ec2 server
ubuntu#ip-10-166-185-18:~$ sudo netstat -nup -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:68 0.0.0.0:* 400/dhclient3
Telnet uses port 23, you don't have it in your security group.
type this:
JP$ telnet passionat4.net 80
80, 443, 3389, or whatever port you're testing for.
Windows example:
C:/> telnet www.google.com 80

Memcached on Mac OSX fails when daemonizing second instance

i want to run memcache deamons on my local mac osx (latest os( machine for developing. when i start the first instance like:
sudo memcached -m 8mb -l localhost -p 11211 -d -vv
everything seems to be ok. if i make a lsof on the port this is how it looks like:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
memcached 614 root 4u IPv4 0xffffff80113eeda8 0t0 TCP adobe-dns.adobe.com:11211 (LISTEN)
memcached 614 root 5u IPv6 0xffffff800c5c97b0 0t0 TCP localhost:11211 (LISTEN)
memcached 614 root 6u IPv6 0xffffff800c5c94a0 0t0 TCP localhost:11211 (LISTEN)
memcached 614 root 7u IPv4 0xffffff800c3b02c0 0t0 UDP adobe-dns.adobe.com:11211
memcached 614 root 8u IPv6 0xffffff800c3af140 0t0 UDP localhost:11211
memcached 614 root 9u IPv6 0xffffff800c3afa00 0t0 UDP localhost:11211
i find this quite strange ... and if i try the second instance on a new port like:
sudo memcached -m 8mb -l localhost -p 11212 -d -vv
i get an error saying:
failed to listen on UDP port 11211
udp listen: Address already in use
even though im starting the daemon on port 11212. can somebody explain or give any hints what this means - what is happening there
THX
Frank
You need to add -U 0 unless you care about UDP support, in which case you'd want to add -U 11212. We straightened this out a bit more in later versions so it does something more intuitive.

Resources