11

I'm building a headless Steam gameserver which utilises Steam in-home streaming to let two people play at the same time. The multiseat part of the setup is done and functional, but getting it to work wireless is quite troublesome.

Only one Steam client can enable in-home streaming at a time. This is most likely due to using the same ports and IP address. How can I assign each user their own IP address?

Streaming will only be done from within the home network. The machine itself already has 3 IPs on a single interface.

21

You can assign different network configuration to a process using linux network namespaces. In theory it should be possible to configure PAM* to set each user in its own separate network namespace, but it is likely simpler to launch the application in question in its own namespace instead.

A common setup might describe creating a Linux bridge interface to connect the namespaces to network. A bit simpler setup can be archived using ipvlan (included in kernel versions 3.19 and above) or macvlan device (for wireless you can't use macvlan). Linux kernel documentation has a detailed example for setting up ipvlan in network namespace.

Following the example in the documentation:

  1. Create a network namespace ns0

    ip netns add ns0
    
  2. Create ipvlan slave on eth0 (master device)

    ip link add link eth0 ipvl0 type ipvlan mode l2
    
  3. Assign slaves to the network namespace ns0

    ip link set dev ipvl0 netns ns0
    
  4. Configure the slave device in network namespace ns0

    ip netns exec ns0 ip link set dev ipvl0 up
    ip netns exec ns0 ip link set dev lo up
    ip netns exec ns0 ip -4 addr add 127.0.0.1 dev lo
    ip netns exec ns0 ip -4 addr add $IPADDR dev ipvl0
    ip netns exec ns0 ip -4 route add default via $ROUTER dev ipvl0
    

    Provide host and router addresses in $IPADDR and $ROUTER.

  5. Run your application in network namespace using ip exec

    ip netns exec ns0 <command>
    

    To run the command as different user, use the usual su <user> -c -- <command>.


* EDIT: From theory to practice: I've written a simple PAM module to demonstrate how to change the network namespace per user. You need to configure a network namepsace with ip netns like above and map specific users to specific a namespaces. Afterwards all user processes will be in their configured namespace instead of the default one. The code is hosted on github. Use at your own peril.

  • your second command does not work for me on ubuntu 14.04 I only get: Garbage instead of arguments "mode ...". Try "ip link help". – Sim Sep 19 '17 at 8:30
  • 1
    I've updated the answer with kernel version, Ubuntu 14.04 is doesn't seem to include recent enough kernel version. I can't think of a workaround that allows you to configure separate IP addresses when you are using wireless. If you are using Ethernet, you can just replace ipvlan with macvlan in command 3 and follow the rest of the example. – sebasth Sep 19 '17 at 8:40
  • you mean in command 2? The variables $IPADDR and $ROUTER have to be provided by me or are those already set? – Sim Sep 19 '17 at 8:46
  • 1
    Indeed command 2. You have to provide your own network configuration. – sebasth Sep 19 '17 at 8:47
  • 2
    @Sim good catch, it didn't. Corrected the answer, the namespace needs to be specified after the exec keyword like in other parts of the example. – sebasth Sep 19 '17 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.