Jump to content
relink

Change Default Gateway on Docker container?

16 posts in this topic Last Reply

Recommended Posts

I am loving the fact that we can now easily assign docker containers custom IPs, but is there anyway to also change the default gateway for a container? I would like to do this so I can route specific containers through my VPN client that is on my network.

 

I assume its probably something simple that I just overlooked.

Share this post


Link to post

When the Docker service is started it will read the current gateway setting belonging to each available network.

 

Docker doesn't allow to set a different gateway for individual containers. Your best bet is to use a different network for those containers which you want to route differently. This can be achieved without new wiring If your switch and router support VLANs.

 

Share this post


Link to post

is it possible to keep the same subnet so my containers will still have IPs in the 192.168.1.x rage?

Share this post


Link to post

Yes, that  is possible. Though you need to give unRAID itself a different IP address as used on the main interface. E.g

 

Main interface

unRAID = 192.168.1.2/24

gateway = 192.168.1.1

 

VLAN interface

unRAID = 192.168.1.3/24

gateway = 192.168.1.254

 

Share this post


Link to post

That sounds like it would accomplish what I need. I have never setup anything like that before though. Would you be willing to guide me in the right direction? I am using a Synology RT1900 router and I’m sure it supports VLANS

Share this post


Link to post

Do you have any switch in the middle or is your unRAID server directly connected to the Synology router?

 

Share this post


Link to post

I have a DLink 24port switch its the DGS-1100-24 Gigabit Ethernet Switch.

 

Everything goes through the switch, then to the router, but the router handles all the DHCP and everything.

Edited by relink

Share this post


Link to post

Start reading this topic. It should help you to configure the unRAID side.

 

Looking at the user guide of the Synology RT1900ac it says that a VLAN can be configured for VOIP under Network center -> Local network -> IPTV & VoiP. I presume we can use that here for the Docker communcation.

 

Also your D-Link switch must allow VLAN tagged traffic to pass. You'll need to check that or use a direct connection between router and unRAID instead.

 

Share this post


Link to post

I’m currently scoring the manual for my switch, not 100% what they would call that, but considering the tons of times “VLANS” are mentioned, I would imagine it’s in here somewhere.

Share this post


Link to post

The D-Link switch supports VLANs.

 

Configuration is under 802.1Q VLAN Settings.

image.png.577ee22f4f85aaf7a1aca090537f4d1b.png

On this page you need to enter the VID (VLAN) number and select both the port to which the unRAID server and the port to which the router is connected as "Tagged".

Edited by bonienl

Share this post


Link to post

Ok that seems simple enough. What is theVID? Is that just a random number I can assign?

 

also my unraid is connected using a bond of 4 Ethernet cables, should I mark all 4?

Edited by relink

Share this post


Link to post

Just coming back to let you know I didnt forget about this, I just realized I had several other issues going on with my network that I am going to fix today, and my little one is teething right now so I got nothing done yesterday. I should be getting back to setting up this VLAN either today or tomorrow.

 

Based on the info you gave me im going to go ahead and take a stab at it (hopefully today), but I have a few questions;

1. where do I define what IP I want as the default gateway? Is this done in Unraid, or my router?

2. Can I also use this VLAN for other devices on my network or will it be restricted just to unraid?

Share this post


Link to post
On 1/15/2018 at 12:28 PM, bonienl said:

Yes, that  is possible. Though you need to give unRAID itself a different IP address as used on the main interface. E.g

 

Main interface

unRAID = 192.168.1.2/24

gateway = 192.168.1.1

 

VLAN interface

unRAID = 192.168.1.3/24

gateway = 192.168.1.254

 

This is exactly what i would like to do but does not seem to work. After i create the VLAN, under settings docker the default gateway for the vlan i created is blank.

 

My goal is to have 2 dockers point to a different default gateway than the unraid server. All while keeping the same subnet as unraid.

 

unraid - 192.168.1.150/24  -- default gateway - 192.168.1.1

docker1 - 192.168.1.20/24 -- default gateway - 192.168.1.200

docker2 - 192.168.1.21/24 -- default gateway - 192.168.1.200

 

Is this possible without a managed switch? Any help much appreciated.

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.