I have seetup a docker host with a couple of services. One of them ar phpipam.
When I ping from phpipam i want it to come from a specific ip adress.
our host has one nic with several adresses: 192.168.1.4, 192.168.1.5, 192.168.1.6 etcetera
Network is 192.168.1.0/24 and default gw 192.168.1.254
the part in my docker compose for the web-service is like this:
I have no configuration in the compose for network except the the one in ‘ports;’
I can reach the application from
http://192.168.1.7 but when I do a ping from the application it comes from adress 192.168.1.4. How can I make it to come from 192.168.1.7?
It is possible to set the IP to use for container outbound traffic, search for
- subnet: 192.168.0.0/24
I didn’t even know about this. I tried now and worked. I only added the label without the static subnet. If you made it a topic in
Tips & HowTos that would quickly become a frequently referred topic. I couldn’t find it in the documentation even though it seems it has been there for years:
05:13AM - 25 Sep 19 UTC
This commit allows a user to specify a Host IP via the
I added this to the end of my compose:
- subnet: 192.168.1.0/24
I then exec into phpipam-web and run a ping command an can see in our firewall that the ping still comes from the hosts ip-adress.
What is your Docker version?
I guess the problem is that you have a single interface with multiple ip addresses. So the traffic will go to the interface which has the ip address set in the label but it will still go through that single interface so the remote will see the default ip. You could try to create separate interfaces for the ip addresses.
I also edited your post as your previous post before. Please, format your posts according to the following guide:
How to format your forum posts
In short: please, use
</> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.
My Docker version is 24.0.5
OS is Ubuntu 22.04
I installed it two weeks ago and applied all patches.
How do I setup another interface on the same subnet?
the interface I have is ens160. I added another interface ens192.
Here are my netplan config before adding the new interface:
- to: default
Thank you for editing the code in my previous reply and thank you for your time helping me with this case.
I tested to deploy another container with some network tools:
My docker compose is like this:
- subnet: 192.168.1.0/24
When I exec into it and run a ping I can see in our firewall that the ping comes from 192.168.1.7 and the ping is allowed by the firewall but I do not get any responce on the ping.
Another thing i noticed is that the container gets ip-adress 192.168.1.2. That address is used by another server in our network.
When i put the
section in the compose for phpipam and starts it ant exec into phpipam web and do a ping it comes from ip 192.168.1.4.
Why does it come from 192168.1.7 when i have it in one compose and not in another?
phpipam is working for me now.
I skipped the subnet part of networks default. Now it looks like this:
(I only have one NIC in the docker host. It wasn’t needed to add another NIC ass suggested).
I tested to skip the ipam-part as well and it still works. Now it looks like this:
Maybe I could skip the ‘driver: bridge’ as well.
With this configuration you assigned the lan’s subnet to the bridge’s IP Address Management. It is not designed to be used like this. It must be a different subnet than the lan’s subnet.
If you look at the example of
@bluepuma77 , he specified a subnet that is not in the lan’s subnet.
@thonyj I’m glad to see that despite my misleading answer everything works now.
Thank you @meyay, I should have noticed that too.