mojira.dev
MC-473

Linux users can't open to lan because it's binded to 127.0.0.1

When you click on "open to lan", the game takes the loopback interface as the one to get the ip address. so it binds to 127.0.0.1 and no one but you can connect to the game.

Related issues

Comments

Ezekiel

can you direct connect to the IP shown?

Eddy B.

This happened to me, but for 127.0.0.2.
It turns out Minecraft uses the local hostname to get the IP facing LAN, but /etc/hosts only has a default 127.0.0.2 IP.
I'm using NetworkManager and I think it fails to alias the hostname to the IP it gets from DHCP.
To quote from IRC:
"the way I did it in one of my node.js projects is I got the IP of the first externally visible network interface (node.js provides that information, Java may have something similar)"

Eddy B.

I forgot to mention, to workaround this problem, add "external-ip local-hostname" to /etc/hosts.
You can get the external-ip with /sbin/ifconfig and the local-hostname with /bin/hostname.

pancake

the ip shown is 127.0.0.1. you can't connect to localhost if you are not running minecraft in localhost πŸ™‚

Ezekiel

Just checking

Simon McVittie

Previously reported against 1.3.2 on the Minecraft wiki. Here's my more detailed report from there:

"""
On Debian, /etc/hosts usually maps the laptop's own hostname to 127.0.1.1, an alternative loopback address (e.g. "127.0.1.1 mylaptop.mydomain mylaptop" - all of 127.0.0.0/8 is loopback).

When a Minecraft-on-Debian user advertises their single-player game to the LAN, the multicast announcement comes from their LAN IP address (e.g. 192.168.0.2), but the server only listens on 127.0.1.1 and announces that address in the multicast packet, e.g. [AD]127.0.1.1:58388/AD, making other machines unable to join.
"""

(From other people's comments here, it seems other Linuxes end up with 127.0.0.1 or 127.0.0.2.)

The cause is that InetAddress.getLocalHost().getAddress() is pretty useless on Linux: it assumes that gethostname() returns a DNS name that resolves to the an address usable by other players, which isn't generally true.

Here is a patch relative to the MCP 7.2 semi-deobfuscated source, hopefully it'll be easy enough to make the corresponding change in the real Minecraft source code:

http://www.pseudorandom.co.uk/~smcv/minecraft-1.3.2-lan-server-v4.diff

Here is permission to do what you like with that patch, including incorporating it into Minecraft: copying and distribution of the patch, with or without modification, are permitted in any medium without royalty. The patch is offered as-is, without any warranty.

Simon McVittie

According to Zorander on the wiki, this might be a problem on Mac too:

"This is actually an issue with any OS except Windows, due to the loopback interface."

Simon McVittie

Further explanation of the changes I suggest:

1) listen on 0.0.0.0 or :: instead of specifying a particular listening address

2) when sending AD packets to the network, if they would contain 0.0.0.0, fill in something else, to be nice to unpatched versions (getLocalHost() is a reasonable fallback)

3) when receiving an AD packet from the network, ignore the IP address appearing before the ":", and use the IP address from which the packet was received (together with the port from after the ":" as usual)

Finn Herzfeld

#3 won't work, because the server doesn't actually listen on 0.0.0.0 or ::. It binds to the loopback interface, meaning that even if someone types your IP in manually they won't be able to connect.

Erik Broes

Future will bind to 'null' (which ends up being INADDR_ANY) now.

Ilan Berlinbluv

Quick fix: (On ubuntu, since I use it. Instructions may vary according to distro)(ROUTER ONLY!)
1) Open Terminal, type in "hostname", press Enter, write it down. (Mine was "Ilanz0r")
2) In the terminal, type in "sudo gedit /etc/hosts" and type in your password when asked for it.
3) In the text that opens, form a new line just under the first line (should be an IP and a tab afterwards, followed by a name)
4) On the new line, copy in your internal IP (mine is 192.168.2.105), press TAB to insert a long space, and then type in your hostname exactly, to make it look like this:
EXAMPLE:
192.168.2.105 Ilanz0r
5) Save it, see if it works πŸ™‚
(You have to change this every time you connect to a new wifi unless you set a static IP)

Jan Zidaric

it says that is it fixed on 1.4.4 i downladed it opend to lan it said:
local game hosted on 0.0.0.0:53962 then i tryed connect on another computer it apeard in the multiplayer menu
but when i tryed to join it said connection refused so its not fixed not for me anyway
i think its cuze server can use 0.0.0.0 to accept connections from anywere but client cant connect to 0.0.0.0 cuze client needs to use the ip of the computer it connects to
cuze when it displays the server in the multiplayer menu it uses 0.0.0.0

Jennifer

Yeah this isn't fixed for me, either. (Arch Linux) I even have net-tools (with ifconfig) installed, if it makes a difference. When I open a world to LAN, the IP address comes up as 0.0.0.0 with a port.

David Bruguera TornΓ©s

it don't work for me too, it shows 0.0.0.0 and the other computer can't connect U.U please reopen the bug

Simon McVittie

As I said on #MC-2549, it looks as though my suggestion (1) from https://mojang.atlassian.net/browse/MC-473?focusedCommentId=15647&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-15647 has been done, but (2) and (3) have not. At least (3) is necessary to resolve this bug.

Eddy B.

READ THIS FIRST BEFORE COMMENTING

0.0.0.0 means "accessible to all network interfaces", so anyone can connect if they know your real IP and the random port Minecraft gives you. If you're in a LAN, run "/sbin/ifconfig" in a terminal (without quotes), that will give you your local IP, then use LocalIP:PortGivenByMinecraft to connect from another PC on the LAN, to the linux LAN server.

The actual problem, that Simon is trying to emphasize, happens when Minecraft tries to connect to a linux LAN server, because it uses 0.0.0.0 as a real IP (which it's not), instead of the actual IP that the broadcast (announcing a LAN server) is coming from.

My reddit post with an example: http://www.reddit.com/r/Minecraft/comments/136ipr/144_is_now_live_on_the_launcher_bukkit_dev_build/c71ca3h

bobby pomranky

while 0.0.0.0:[randomport] does mean accessible to all network interfaces, it is not at all user friendly being it a LAN server, No-one wants to type in their lan address everytime they want to play (being it the fact a random port is given everytime. it was nice the way it was pre-1.4.3

Oliver Okum

Seems to happen for Mac Users in 1.4.4. Take a look aat this issue: MC-3097

Simon McVittie

Seems to work correctly in the 1.4.5 prerelease (Linux LAN server, Linux client). Thanks!

Jan Zidaric

works fine on 1.4.5 1.4.6 1.4.7 (Linux LAN)

Stirling

Its not just Linux users windows users cant

Erik Broes

If you 'Open to LAN' the idea is that you will connect to the server via the 'Scanning for LAN Worlds' in the Multiplayer menu. All available worlds will show up and they are found using multicast (so unless you have some crappy setup that somehow disables that – you can just find the worlds in that menu). The multicast will know the right IP to connect to so you do not need to know the IP at all. I think we should perhaps disable the display of the IP when you've turned on 'Open to LAN', so it just says: LAN world listening on port: xxxx.

Furthermore the code binds to all available interfaces (using INADDR_ANY), this also means it should bind to 127.0.0.1 as that should exist as your local loopback device, as well as to any IPV4/6 interfaces available to java.

So, if you say you have problems, please give exact details on what you are using and how you have set it up. Also be aware your local firewall might be preventing multicast or outside connections, this however is not something Mojang can solve/help with.

Maarten Thijs

@Grum is this related to this problem?
https://mojang.atlassian.net/browse/MC-2555

Liam Dawe

Just FYI using Minecraft 1.4.6 on Linux (Kubuntu 64bit, openjdk 7) I made a single player world, my mrs on her mac was able to connect to me perfectly so the issue is gone for me? But when she on her mac tried it i couldn't connect to her so is it really a Linux issue?

Stirling

Mojang have now fixed this but for non-linux users: https://www.youtube.com/watch?v=8CaWO_tPVXE

Jan Zidaric

@Stirling IT HAS BEEN FIXED ON LINUX SINCE 1.2.5
I HAVE NOOO IDEA WHOO REOPEND THIS CUZE IT WORKS 100% on windows linux and mac

Erik Broes

As far as I know this problem actually always is a user firewall/network configuration issue. I'll be closing this issue unless anyone can prove otherwise πŸ™‚

shufboyardee

Grum, if you are prepared to say you are 100% sure that this always happens via a user firewall/network configuration issue, perhaps then, opening to lan failure could trigger a screen explaining several troubleshooting steps the user could take, similar to how browsers often deal with network failure. Abiding by the principle of giving helpful error messages, and making it clear that system configuration is at the heart of the matter.

Erik Broes

I'm 99.9999% sure it is always firewall/network configuration and obviously there is no way to detect this.

There is no 'failing' in 'open to Lan' because you ALWAYS have a loopback device it can open a port on. This means there is no way to display such a screen.

IMHO People who use a firewall should know how to use it πŸ™‚

shufboyardee

Fair enough.

Tails

Is this still a concern in the current Minecraft version? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

Tails

The main issue was fixed, if you still having difficulties connecting check you firewall/router settings. For additional technical support please use the Mojang Support Center.

pancake

Erik Broes

Community Consensus

Minecraft 1.4.1, Minecraft 1.4.2, Minecraft 1.4.4

Retrieved