How to disable loopback interface in Linux (Fedora)? - linux

So that requests to localhost are treated as if coming from remote host in LAN?

Have you tried updating your /etc/hosts file, replacing:
127.0.0.1 localhost
With your actual IP address? e.g.,
192.168.0.42 localhost
(This doesn't actually disable the loopback address, you can still connect to 127.0.0.1, but connecting to localhost should come in through your network interface, which I believe is what you're asking)

Related

Why can I connect to Mongo in node using 127.0.0.1, but not localhost?

I'm connecting to Mongo using the Node library, and mongo is up and running on port 27017.
If I set my uri to mongodb://127.0.0.1:27017 it connects, but if I set it to mongodb://localhost:27017 it doesn't connect (times out).
I'm on Linux, and my /etc/hosts looks like this:
127.0.0.1 localhost
::1 localhost
My guess is it has something to do with ipv6, but I have very little understanding of ipv6 to be honest. Can someone explain what's happening here, and if I should do something differently to be able to connect to localhost?
As you pointed out, it seems that localhost resolves to IPv6 address ::1 and not 127.0.0.1.
You can keep using 127.0.0.1 or another option would be changing the address mongod service binds to, for instance, ::1 (you can bind to IPv4 and IPv6 at the same time).

Linux process/component sending frequent DNS queries to resolve the local hostname (but shouldn't)

I'm not a networking guru so could use some help. I am running a RHEL7 (Red Hat Enterprise Linux) VM (Virtual Machine) where some component on the OS is sending frequent DNS queries to resolve it's own local hostname to our main DNS server (which shouldn't be happening because the DNS server won't know anything about its address). Can anyone provide guidance as to how I can find out what component/service/process this is? It's filling our logs with 19k records over just hours and I need to find a way to fix this.
The hostname for the RHEL VM is spe1.2v29999999.dev.local , there is a static IP on this VM and it is 10.70.49.61. The /etc/hosts looks like:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost4 localhost4.localdomain4
I suspected it might be a java jar we have running on the VM, but I stopped it via systemctl stop MyJavaJar but after running a tcp dump via tcpdump -i any udp port 53, I could still see the queries happening.
Here are some examples from different days/times in the logs (both A and TXT records):
2020-05-05T13:53:50.189178+00:00 dns.green.blue.mycompany.com 127.0.0.1 <daemon.info> dnsmasq[20886]: 739 10.70.49.61/65078 query[A] spe1.2v29999999.dev.local from 10.70.49.61
2020-05-07T00:01:39.934899+00:00 dns.green.blue.mycompany.com 127.0.0.1 <daemon.info> dnsmasq[8615]: 27827 10.70.49.61/57348 reply spe1.2v29999999.dev.local is NXDOMAIN
2020-05-11T00:01:20.674688+00:00 dns.green.blue.mycompany.com 127.0.0.1 <daemon.info> dnsmasq[8615]: 130345 10.70.49.61/53321 query[TXT] bootstrap.spe1.2v29999999.dev.local from 10.70.49.61
Would making any changes to /etc/hostname, /etc/sysconfig, /var/named .zone files, /var/named.conf or /etc/named help? Can I do more with tcpdump? Thanks
Put:
127.0.0.1 spe1.2v29999999.dev.local
in /etc/hosts. This is done by default on many distros.

can't telnet via IP but can via localhost

I started an instance on AWS ec2 and am trying to connect via my web browser to the app on the server running on port 3000. I've also turned off iptables...
I can telnet via telnet localhost 3000 and telnet 127.0.0.1 3000 but can't telnet via the hostname or ip like telnet ipaddress 3000.
When i do that, I get a connection refused. I think this has somethign to do with my hosts file but can't figure out what. My host file looks like this:
127.0.0.1 ip-108-205-72-168
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost6 localhost6.localdomain6
Provided that you gave the instance a public ip, have you checked the security groups? AWS security groups are associated with instances and apply inbound/outbound rules.
If you have already done that then my next step would probably be to make sure that the port is bound to the correct interface(s). ss -tupan | grep 3000
please make sure you iptable rules is right and can accessed by ip.
Could you confirm whether you using elastic IP over the amazon VM?
If yes, then it will do the entry in the host file automatically when you associate elastic IP to the EC2.
But if not, then need to do a manual entry.
Thanks,
SIM

How to configure apache in local development in rails

I am trying setup a loacl domain on my pc for that I have apache server install I want to open my rails s inside this abcd.com instead of 127.0.0.1:3000. In my host I have changed host file like this:
127.0.0.1 localhost
127.0.0.1 abcd.com
But when I am trying to open abcd.com with this command I am getting this message:
Address already in use - bind(2) for "127.0.0.1" port 80 (Errno::EADDRINUSE)
When I stop apache it works on localhost any help
You need to write all hostnames behind the ip like this :
127.0.0.1 localhost abcd.com

How to disconnect from localhost?

Is it possible to disconnect from localhost?
I'm writing a Node.js WebSocket server, and I want to test locally what would happen if the connection closes erroneously.
If I were testing remotely, I'd just Turn Wi-Fi Off, but that doesn't disconnect my connection to localhost.
Thoughts?
localhost is just an alias in your hosts file. If you remove that alias then you'll be effectively "disconnecting" from localhost.
I don't know of any way you would do what your asking except perhaps to block the ports or the program you are running on your localhost via its firewall.
As David mentioned, you can block ports with a simple firewall.
For example on OSX, to block localhost on port 8080
$ sudo ipfw add deny tcp from any to localhost 8080
Will return a response like:
00100 deny tcp from any to 127.0.0.1 dst-port 8080
And then to remove the rule:
sudo ipfw delete 00100
(ipfw is deprecated in favor of pfctl, but I still find it simpler for these purposes)
Instead of using localhost, I use the IPv4 address (which can be obtained using ipconfig call or looking into Local Area Connection) to access local machine, and then, to simulate network failure, I just disable Local Area Connection. It helps me test network failures on local machine.

Resources