Change Container MAC and IP address

Hello,

I have a server with many services which I will move into docker for handling of different network interfaces. I need a fixed IP address and a fixed MAC address for every service to configure the Fitz!Box VPN access. The Fritz!Box can only filter on hand of the MAC address and configured it on hand of the IP address. It is not fine, but I can’t change it.

Now I’ve started my first test with ngix docker (simpel with default page):

tester@a1:~/docker run --name my-nginx -d -p 8080:80 nginx

tester@a1:~/docker$ docker container ls
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS         PORTS                                     NAMES
8f1b8aa094d5   nginx     "/docker-entrypoint.…"   10 seconds ago   Up 9 seconds   0.0.0.0:8080->80/tcp, [::]:8080->80/tcp   my-nginx

This can I test with open the webpage 192.168.7.27:8080, where the IP is the host IP. And this work.

After this I create my own network with:

tester@a1:~/docker network create -d macvlan --subnet=192.168.7.0/24 --gateway=192.168.7.1 -o parent=eno2 net-nginx

tester@a1:~/docker$ docker network ls
NETWORK ID     NAME        DRIVER    SCOPE
f754992ec3d7   bridge      bridge    local
f4e13623c4cf   host        host      local
7d460c43eb8f   net-nginx   macvlan   local
8504b0e350b3   none        null      local

Now start nginx to a fixed IP address in the new network:

tester@a1:~/docker$ docker run --net net-nginx --ip 192.168.7.111 --name my-nginx-111 -d -p 8080:80 nginx

The test with open the webpage fails!

The network self is correct configured for me:

tester@a1:~/docker$ docker network inspect net-nginx
[
    {
        "Name": "net-nginx",
        "Id": "8c8eeab402ed626a49e9aeffeed53d503a2436d071df1398c1ffa596b0defd0a",
        "Created": "2025-03-20T12:51:26.047235535+01:00",
        "Scope": "local",
        "Driver": "macvlan",
        "EnableIPv4": true,
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.7.0/24",
                    "Gateway": "192.168.7.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "bbcf972d9ea33ccb5fdf64eda2986f3bd9af043195c8ecbf06562148bdbf02bf": {
                "Name": "my-nginx-111",
                "EndpointID": "30e268295350da9423ea01717b6e3e19213cc5f3bb197857e22ee3d3bd3961bc",
                "MacAddress": "0e:5d:6e:3e:75:98",
                "IPv4Address": "192.168.7.111/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "parent": "eno2"
        },
        "Labels": {}
    }
]

Now I will test it with ping, it is easier and faster. So I’ve generate a debian docker with a fixed IP address:

tester@a1:~/docker$ docker run -it --name my-debian --net net-nginx --ip 192.178.7.111 -P debian bash

In the bash of the docker I can ping my other machines in the network. That works. A ping from a other machine to the my-debian dosn’t work.

What I missing is the port configuration of booth not working machine:

tester@a1:~/docker$ docker container ls -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                       NAMES
b24666900b04   debian    "bash"                   12 minutes ago   Created                                                     my-debian
bbcf972d9ea3   nginx     "/docker-entrypoint.…"   19 minutes ago   Up 19 minutes                                               my-nginx-111
c1f1e206058d   nginx     "/docker-entrypoint.…"   22 minutes ago   Up 22 minutes   0.0.0.0:32768->80/tcp, [::]:32768->80/tcp   my-nginx

All three containers create with -P and only the my-nginx have a port configuration.

What must I do that works? And how can I configure the MAC address?

Thanks for our help,
Bernd

I don’t know where you try to access the webpage from, but if on the same machine where you run Docker using MacVLAN, search for MacVLAN shim. It was discussed on the forum so many times that Google returns it as second (to me) where @meyay wrote about it

Regarding ports, there are no forwarded ports when using MacVLAN. There is no need for it since you already have the IP to use directly. Which would work from another machine (unless a firewall blocks it)

Thanks for youre answer rimelek,

sorry the link what you have postet describe not my problem and give me no solution. WSL2 is MS-Windows. And the Linux what runs under WSL2 is not a native Linux. It give me only a shell like Linux and some functions, but not all.

I have a Debian 12 installed. On the machine I have no forewall running. It is only a test machine, with minimal software and so on.

Now I will read more in the google and hope that I found the solution for me.

What WSL2 is is not really relevant here. I shared the link only to read about MAcVLAN shims which I never needed as I never use MacVLAN and even if I test it, I never need to acces the container from the same machine. Since you didn’t noted after my response that you are trying from another machine, I assume I was right and you are trying from the same machine. Since your network is a macVLAN, the method described in the other topic is still relevant, WSL2 is not. I’m aware of that it is a vitual machine where WSL2 distributions are containers, but if the commands worked for @meyay in a WSL distribution, it should work for you on Debian :slight_smile: