Multiple LAN servers on same linux box

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
zombie
Traffic Manager
Traffic Manager
Posts: 153
Joined: 19 May 2005 22:19
Location: Germany

Multiple LAN servers on same linux box

Post by zombie »

Hi there.

I would like to host two OpenTTD LAN servers on my linux box. I set the port on both servers to different ports (nightly has 3979, official has 3980). Both servers start just fine but I can only see the nightly server in the server browser.

Is it not possible to host two LAN servers on the same linux box or do I have to add another IP address to my network interface and bind both servers to different IP adresses?

Thanks for your help.

Kind regards.

Zombie
User avatar
glx
OpenTTD Developer
OpenTTD Developer
Posts: 622
Joined: 02 Dec 2005 15:43
Location: Drancy(93) - France
Contact:

Post by glx »

Just set server_port in [network] section of openttd.cfg (a different port for each server), and it should work like you want.

[edit]
I just tried, and I can start 2 servers (using different port) and it works.
But as you said, only one server is visible in network game list.
To see the other server, just "add server" and type "server_ip:other_port" and it will appear in the list.
Last edited by glx on 17 Apr 2006 13:54, edited 1 time in total.
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Post by gigajum »

ever tried

Code: Select all

me@mybox:~/openttd$ ./openttd --help
there it showes

Code: Select all

-c config_file      = Use 'config_file' instead of 'openttd.cfg'
with 2 config files you can setup different servers on the same machine with using the same game files (only different config files).

To the openttd.cfg where you need to change the port, take a look @ http://wiki.openttd.org/index.php/Openttd.cfg

You also can use the -n parameter to start a network server, but i'll think the best is you try it yourself.
zombie
Traffic Manager
Traffic Manager
Posts: 153
Joined: 19 May 2005 22:19
Location: Germany

Post by zombie »

glx wrote:I just tried, and I can start 2 servers (using different port) and it works. But as you said, only one server is visible in network game list. To see the other server, just "add server" and type "server_ip:other_port" and it will appear in the list.
This works but I have to tell everone the IP and port of the server. That's not really an option.
gigajum wrote:ever tried

Code: Select all

me@mybox:~/openttd$ ./openttd --help
there it showes

Code: Select all

-c config_file      = Use 'config_file' instead of 'openttd.cfg'
with 2 config files you can setup different servers on the same machine with using the same game files (only different config files).

To the openttd.cfg where you need to change the port, take a look @ http://wiki.openttd.org/index.php/Openttd.cfg

You also can use the -n parameter to start a network server, but i'll think the best is you try it yourself.
As I want to start to different versions of OpenTTD both versions have their own directory and their own config file. And that does not help a bit. The "-n" parameter is used to start OpenTTD as a client for a network game and not as a server.

Kind regards.

Zombie
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Post by gigajum »

zombie wrote: As I want to start to different versions of OpenTTD both versions have their own directory and their own config file. And that does not help a bit. The "-n" parameter is used to start OpenTTD as a client for a network game and not as a server.
Ooooops :( ok, my mistake.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

Check your firewall / NAT settings.. it smells that is wrong/broken.
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

There's no problem whatever in running more than one server on a Linux box. If you want them both to appear on the browse list for LAN games, by far the simplest way to do it is to give the Linux server another IP address for each game server you want to run.

You need to be root to do this. The following instructions will give your Linux machine an extra IP address until the machine is rebooted. If you want a permanent extra IP address, the means of (properly) making it permanent will vary from distribution to distribution.

OK, here we go.
  1. First, identify a spare IP address on your network. I'm going to assume for the purposes of this demonstration that your server has the address 192.168.0.2, and your workstations(s) are being given addresses like 192.168.0.3, 192.168.0.4 etc by your router. I'm also assuming that your netmask is 255.255.255.0 and your broadcast address is 192.168.0.255. You can use the ifconfig to determine your IP address settings:

    Code: Select all

    # ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:21:83:FE:4F:15
              inet addr:192.168.0.2  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::230:84ff:feee:4f05/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:34806 errors:0 dropped:0 overruns:0 frame:0
              TX packets:26603 errors:0 dropped:0 overruns:5 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:31640314 (30.1 Mb)  TX bytes:7714251 (7.3 Mb)
              Interrupt:10 Base address:0xaf00
    
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:78 errors:0 dropped:0 overruns:0 frame:0
              TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:5948 (5.8 Kb)  TX bytes:5948 (5.8 Kb)
    
    Note that your network card is the one labelled eth0 (and there's also an eth1 if you have a second one).

    We grab an arbitrary IP address in the 192.168.0.* range that we don't think will already be in use. In this case, I'm going to nearly randomly choose 192.168.0.42 (you can choose addresses as high as .254).
  2. Now we have chosen an IP address, we need to tell Linux to use it.

    The following command will add it:

    Code: Select all

    # ifconfig eth0:0 192.168.0.42 netmask 255.255.255.0 broadcast 192.168.0.255
    There is no feedback at all, so we repeat the ifconfig comand to see the result:

    Code: Select all

    # ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:21:83:FE:4F:15
              inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::230:84ff:feee:4f05/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:38719 errors:0 dropped:0 overruns:0 frame:0
              TX packets:29989 errors:0 dropped:0 overruns:5 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:34694084 (33.0 Mb)  TX bytes:8504493 (8.1 Mb)
              Interrupt:10 Base address:0xaf00
    
    eth0:0    Link encap:Ethernet  HWaddr 00:21:83:FE:4F:15
              inet addr:192.168.0.42  Bcast:192.168.0.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              Interrupt:10 Base address:0xaf00
    
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:78 errors:0 dropped:0 overruns:0 frame:0
              TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:5948 (5.8 Kb)  TX bytes:5948 (5.8 Kb)
    That's it. You don't need to reboot anything or restart anything, and you can now ping that IP address from anywhere on the network.

    To add even more IP addresses, just repeat the above, but keep adding to the number after the colon - eth0:1, eth0:2 etc.
  3. You don't need to be root for any of the rest of this. In the network section of your different openttd.cfg files you need to tell each openttd server to use a different IP address...

    Code: Select all

    [network]
    max_join_time = 500
    pause_on_join = true
    server_bind_ip = 0.0.0.0
    server_port = 3979
    server_advertise = false
    Change the server_bind_ip value to one of your IP addresses. Give each server a different one, as in this example:

    Code: Select all

    [network]
    max_join_time = 500
    pause_on_join = true
    server_bind_ip = 192.168.0.42
    server_port = 3979
    server_advertise = false
    They can all use the same port, which is an added bonus.
  4. Now, simply start each server with the openttd -D command or variant that you already use.
Let me know if any of this needs clarifying. If you're at your PC and want help with this, feel free to IM me if I'm on line, or find me on ##Linux or #openttd on Freenode IRC.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
zombie
Traffic Manager
Traffic Manager
Posts: 153
Joined: 19 May 2005 22:19
Location: Germany

Post by zombie »

Hi there.

Thanks for your extensive help Brianetta. My linux box already has multiple IP adresses on the same network. But I set it up with multiple network cards (3) using advanced routing to have a dedicated NIC for games, samba/ftp and other services.

I will try to add another ip address to the gaming interface (can be challenging with advanced routing) or I will set up one of the OpenTTD servers to use my spare NIC.

Kind regards.

Zombie
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

Linux should route as well as it ever does - just bear in mind that regardless of how carefully you set it up, if different physical network cards are on the same network you can't guarantee which one Linux will send outgoing packets through. This only matters if your network isn't "normal" (for example, if you have a managed switch with port based QoS).

Just adding extra IP addresses (aliases) to your existing eth devices should pose no problems.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
CharlyHRO
Traffic Manager
Traffic Manager
Posts: 186
Joined: 13 Mar 2006 11:03
Location: ::1

Post by CharlyHRO »

Nice job, Brianetta. But now a special question. What to do, if you host two servers on the same LAN, but someone from the internet wants to join one of the games? Then you have to set up different Port because port-forwarding doesn't know if it should forward to IP (A) or IP (B), right?
moe moe pipebomb
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Post by gigajum »

CharlyHRO wrote:Nice job, Brianetta. But now a special question. What to do, if you host two servers on the same LAN, but someone from the internet wants to join one of the games? Then you have to set up different Port because port-forwarding doesn't know if it should forward to IP (A) or IP (B), right?
Almost right. Port forwarding can only be done from ONE IP:Port -> IP:Port and not to 2 IPs. You need to set on the router two different ports. They can be forwarded both to the same port but on different computer. You also can forward both to the same port on the same machine. But you cannot set up one IP:Port on which you get access to two servers. :)
User avatar
CharlyHRO
Traffic Manager
Traffic Manager
Posts: 186
Joined: 13 Mar 2006 11:03
Location: ::1

Post by CharlyHRO »

gigajum wrote:Almost right. Port forwarding can only be done from ONE IP:Port -> IP:Port and not to 2 IPs. You need to set on the router two different ports. They can be forwarded both to the same port but on different computer. You also can forward both to the same port on the same machine. But you cannot set up one IP:Port on which you get access to two servers. :)
As I said. :wink: But keep in mind -> not every router is able to forward a packet, incoming on port 3989 to the servers port 3979. most routers only forward to the same port at wich the packet is coming in... got it?
moe moe pipebomb
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Post by gigajum »

CharlyHRO wrote:... got it?
No.

Cheap crap (IMO).
User avatar
CharlyHRO
Traffic Manager
Traffic Manager
Posts: 186
Joined: 13 Mar 2006 11:03
Location: ::1

Post by CharlyHRO »

now a question to the developers: if I start two servers on my LAN (hidden behind a router) and both listen on port 3979 AND I tell the router to forward port 3979 to server A port 3979 AND to forward port 3989 to server B port 3979 and both servers are set to advertise themselves, what happens? do both servers get listed with port 3979???
moe moe pipebomb
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

CharlyHRO wrote:now a question to the developers: if I start two servers on my LAN (hidden behind a router) and both listen on port 3979 AND I tell the router to forward port 3979 to server A port 3979 AND to forward port 3989 to server B port 3979 and both servers are set to advertise themselves, what happens? do both servers get listed with port 3979???
Try it and see. I'd guess that server B advertises itself as being at port 3979, which isn't the case, meaning that players connecting to server B might find themselves on server A. Of course, I'm quite prepared to be wrong.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

CharlyHRO wrote:now a question to the developers: if I start two servers on my LAN (hidden behind a router) and both listen on port 3979 AND I tell the router to forward port 3979 to server A port 3979 AND to forward port 3989 to server B port 3979 and both servers are set to advertise themselves, what happens? do both servers get listed with port 3979???
Server A: 3979
Server B: 3979

Router 3979 A
Router 3989 B

Right? Server A will work correctly, server B will not show up on the master server list because it is on the wrong port. That is at least my idea. However you can connect to server B directly if you specify port 3989 in the connection string.
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
User avatar
LKRaider
Transport Coordinator
Transport Coordinator
Posts: 360
Joined: 23 Mar 2005 04:05
Location: Brasil
Contact:

Post by LKRaider »

Maybe add a server option to manually define what will be advertised to the Master Server? (yeah, I know, 'YET Another Option'
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Post by gigajum »

[quote="LKRaider"]Maybe add a server option to manually define what will be advertised to the Master Server? (yeah, I know, 'YET Another Option'
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 29 guests