How can you assign one IP per user?

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x