Setting up bridged LXC containers with static IPsBridging LXC containers to host eth0 so they can have a public IPHow to set the dns on lxc containers staticly?Issue with multiple bridging for KVM hostsBridging LXC containers to host eth0 so they can have a public IPbridging LXC containers to host network with different IP rangeMake LXC containers directly accessable with ipv6Ipv6 over bridged network stops working after some time (Ubuntu LXC)LXC bridge with several IP addressesbridged LXC: container's mac address learned on wrong interfaceSoftether on lxc container with bridged connectionAmazon EC2/VPC LXC Bridge not workingHow to set the dns on lxc containers staticly?
How to apply the "glow" effect to a rectangle with tcolorbox?
Will dual-learning in a glider make my airplane learning safer?
Old black and white movie: glowing black rocks slowly turn you into stone upon touch
How can Iron Man's suit withstand this?
What's the correct term for a waitress in the Middle Ages?
If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?
Get value of the passed argument to script importing variables from another script
Why does a helium balloon rise?
Accidentally cashed a check twice
Is having a hidden directory under /etc safe?
When leasing/renting out an owned property, is there a standard ratio between monthly rent and the mortgage?
Computing the differentials in the Adams spectral sequence
How should I push back against my job assigning "homework"?
You've spoiled/damaged the card
Incremental Ranges!
Please help me identify this plane
Pitch and Volume Compensations for Different Instruments
Does any lore text explain why the planes of Acheron, Gehenna, and Carceri are the alignment they are?
What does War Machine's "Canopy! Canopy!" line mean in "Avengers: Endgame"?
How to decline physical affection from a child whose parents are pressuring them?
How to detach yourself from a character you're going to kill?
Is it possible to kill all life on Earth?
Why was it possible to cause an Apple //e to shut down with SHIFT and paddle button 2?
PhD student with mental health issues and bad performance
Setting up bridged LXC containers with static IPs
Bridging LXC containers to host eth0 so they can have a public IPHow to set the dns on lxc containers staticly?Issue with multiple bridging for KVM hostsBridging LXC containers to host eth0 so they can have a public IPbridging LXC containers to host network with different IP rangeMake LXC containers directly accessable with ipv6Ipv6 over bridged network stops working after some time (Ubuntu LXC)LXC bridge with several IP addressesbridged LXC: container's mac address learned on wrong interfaceSoftether on lxc container with bridged connectionAmazon EC2/VPC LXC Bridge not workingHow to set the dns on lxc containers staticly?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to setup multiple LXC containers on a host, each with public static IPs of their own.
My host is running the latest Ubuntu. It has a single network interface named eth0. The static IPs are pingable from the internet and are named eth0:210, eth0:211... The numbers after the colon are the least significant byte of the addresses. In addition to these interfaces I have br0 setup on the host's public IP. There are also the lo, veth2LPP9A, and lxcbr0 interfaces. The lxcbr0 has the address of a private IP.
The host /etc/network/interfaces looks like:
auto br0
iface br0 inet static
bridge_ports eth0
bridge_fd 0
[...]
So far I've used various online sources, including Bridging LXC containers to host eth0 so they can have a public IP to help me set this up.
The container's config file has:
lxc.network.type = veth
lxc.network.link = br0
I've removed the static lxc.network.ipv4 configuration from this file since it caused problems. When I ran lxc-ls --fancy with this configuration, I'd see the same public IP twice in the output. Additionally, it would mess with the subnet configuration of the container's /etc/network/interfaces.
Speaking of the container's interfaces file, it looks a bit like:
auto eth0
iface eth0 inet static
address [...]
netmask 255.255.255.255
#gateway [...]
dns-nameservers 8.8.8.8
post-up route add [...] dev eth0
post-up route add default gw [...]
post-down route del [...] dev eth0
post-down route del default gw [...]
I had to comment out the gateway and add the route add commands to this file. Otherwise, the container would take minutes to boot.
The /proc/sys/net/bridge/bridge-nf-* files on the host are all set to 0. The /proc/sys/net/ipv4/ip_forward value is 1.
The problem is, even though the container's "route -n" looks like it should, I can't ping out of the container. SSHing to what should be the container's IP, connects me to the host.
EDIT: Removing the container's static IP from the host did help, but now I'm getting a new error. Trying to ping the container from the host results in Redirect HostFrom , New nexthop. The packets are just going from the gateway to the host, repeatedly. Running a traceroute from the host shows that the first stop is at the gateway. Then all of the other routes are * * *. I get the same problem regardless if the container is online or not.
networking bridge static-ip lxc
add a comment |
I'm trying to setup multiple LXC containers on a host, each with public static IPs of their own.
My host is running the latest Ubuntu. It has a single network interface named eth0. The static IPs are pingable from the internet and are named eth0:210, eth0:211... The numbers after the colon are the least significant byte of the addresses. In addition to these interfaces I have br0 setup on the host's public IP. There are also the lo, veth2LPP9A, and lxcbr0 interfaces. The lxcbr0 has the address of a private IP.
The host /etc/network/interfaces looks like:
auto br0
iface br0 inet static
bridge_ports eth0
bridge_fd 0
[...]
So far I've used various online sources, including Bridging LXC containers to host eth0 so they can have a public IP to help me set this up.
The container's config file has:
lxc.network.type = veth
lxc.network.link = br0
I've removed the static lxc.network.ipv4 configuration from this file since it caused problems. When I ran lxc-ls --fancy with this configuration, I'd see the same public IP twice in the output. Additionally, it would mess with the subnet configuration of the container's /etc/network/interfaces.
Speaking of the container's interfaces file, it looks a bit like:
auto eth0
iface eth0 inet static
address [...]
netmask 255.255.255.255
#gateway [...]
dns-nameservers 8.8.8.8
post-up route add [...] dev eth0
post-up route add default gw [...]
post-down route del [...] dev eth0
post-down route del default gw [...]
I had to comment out the gateway and add the route add commands to this file. Otherwise, the container would take minutes to boot.
The /proc/sys/net/bridge/bridge-nf-* files on the host are all set to 0. The /proc/sys/net/ipv4/ip_forward value is 1.
The problem is, even though the container's "route -n" looks like it should, I can't ping out of the container. SSHing to what should be the container's IP, connects me to the host.
EDIT: Removing the container's static IP from the host did help, but now I'm getting a new error. Trying to ping the container from the host results in Redirect HostFrom , New nexthop. The packets are just going from the gateway to the host, repeatedly. Running a traceroute from the host shows that the first stop is at the gateway. Then all of the other routes are * * *. I get the same problem regardless if the container is online or not.
networking bridge static-ip lxc
add a comment |
I'm trying to setup multiple LXC containers on a host, each with public static IPs of their own.
My host is running the latest Ubuntu. It has a single network interface named eth0. The static IPs are pingable from the internet and are named eth0:210, eth0:211... The numbers after the colon are the least significant byte of the addresses. In addition to these interfaces I have br0 setup on the host's public IP. There are also the lo, veth2LPP9A, and lxcbr0 interfaces. The lxcbr0 has the address of a private IP.
The host /etc/network/interfaces looks like:
auto br0
iface br0 inet static
bridge_ports eth0
bridge_fd 0
[...]
So far I've used various online sources, including Bridging LXC containers to host eth0 so they can have a public IP to help me set this up.
The container's config file has:
lxc.network.type = veth
lxc.network.link = br0
I've removed the static lxc.network.ipv4 configuration from this file since it caused problems. When I ran lxc-ls --fancy with this configuration, I'd see the same public IP twice in the output. Additionally, it would mess with the subnet configuration of the container's /etc/network/interfaces.
Speaking of the container's interfaces file, it looks a bit like:
auto eth0
iface eth0 inet static
address [...]
netmask 255.255.255.255
#gateway [...]
dns-nameservers 8.8.8.8
post-up route add [...] dev eth0
post-up route add default gw [...]
post-down route del [...] dev eth0
post-down route del default gw [...]
I had to comment out the gateway and add the route add commands to this file. Otherwise, the container would take minutes to boot.
The /proc/sys/net/bridge/bridge-nf-* files on the host are all set to 0. The /proc/sys/net/ipv4/ip_forward value is 1.
The problem is, even though the container's "route -n" looks like it should, I can't ping out of the container. SSHing to what should be the container's IP, connects me to the host.
EDIT: Removing the container's static IP from the host did help, but now I'm getting a new error. Trying to ping the container from the host results in Redirect HostFrom , New nexthop. The packets are just going from the gateway to the host, repeatedly. Running a traceroute from the host shows that the first stop is at the gateway. Then all of the other routes are * * *. I get the same problem regardless if the container is online or not.
networking bridge static-ip lxc
I'm trying to setup multiple LXC containers on a host, each with public static IPs of their own.
My host is running the latest Ubuntu. It has a single network interface named eth0. The static IPs are pingable from the internet and are named eth0:210, eth0:211... The numbers after the colon are the least significant byte of the addresses. In addition to these interfaces I have br0 setup on the host's public IP. There are also the lo, veth2LPP9A, and lxcbr0 interfaces. The lxcbr0 has the address of a private IP.
The host /etc/network/interfaces looks like:
auto br0
iface br0 inet static
bridge_ports eth0
bridge_fd 0
[...]
So far I've used various online sources, including Bridging LXC containers to host eth0 so they can have a public IP to help me set this up.
The container's config file has:
lxc.network.type = veth
lxc.network.link = br0
I've removed the static lxc.network.ipv4 configuration from this file since it caused problems. When I ran lxc-ls --fancy with this configuration, I'd see the same public IP twice in the output. Additionally, it would mess with the subnet configuration of the container's /etc/network/interfaces.
Speaking of the container's interfaces file, it looks a bit like:
auto eth0
iface eth0 inet static
address [...]
netmask 255.255.255.255
#gateway [...]
dns-nameservers 8.8.8.8
post-up route add [...] dev eth0
post-up route add default gw [...]
post-down route del [...] dev eth0
post-down route del default gw [...]
I had to comment out the gateway and add the route add commands to this file. Otherwise, the container would take minutes to boot.
The /proc/sys/net/bridge/bridge-nf-* files on the host are all set to 0. The /proc/sys/net/ipv4/ip_forward value is 1.
The problem is, even though the container's "route -n" looks like it should, I can't ping out of the container. SSHing to what should be the container's IP, connects me to the host.
EDIT: Removing the container's static IP from the host did help, but now I'm getting a new error. Trying to ping the container from the host results in Redirect HostFrom , New nexthop. The packets are just going from the gateway to the host, repeatedly. Running a traceroute from the host shows that the first stop is at the gateway. Then all of the other routes are * * *. I get the same problem regardless if the container is online or not.
networking bridge static-ip lxc
networking bridge static-ip lxc
edited Apr 13 '17 at 12:14
Community♦
1
1
asked Feb 2 '14 at 22:40
EthernetCableEthernetCable
176117
176117
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
In fact you can set the address and gateway from within the host and configure the container not to touch the interface at all using the keyword manual
.
Place this within the guests /etc/network/interfaces
:
auto eth0
iface eth0 inet manual
Also leave it up to the container's config file to set up the interface:
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxc-bridge-nat
lxc.network.ipv4 = 192.168.100.16/24
lxc.network.ipv4.gateway = auto
The guest will behave like it's BIOS already set up the interface and just use it.
Especially explore lxc.network.ipv4.gateway
.
Thx! This saved my life... my container would always try to get a new dhcp address... setting it to a fixed value inside the container (static) resulted in the container not even booting anymore!
– Dominik Dorn
Jul 21 '14 at 10:36
Note that this doesn't work well if the host is suspended and resumed. The lxc continues with its allocated ip-address but the host thinks it doesn't have an ip-address anymore. I have found it is better to configure the dnsmasq for lxc-net and handout a fixed address there.
– HRJ
Aug 19 '14 at 12:40
@HRJ - You should include the 'how' in your comment or link to the ref rather than just saying 'do it'. This is a technical site and you should say something actually useable.
– Ian Macintosh
Aug 19 '15 at 22:14
2
It seems like the correct place to do this is both in /etc/default/lxc where you can set your range (see LXC_DHCP_RANGE) and in /etc/dnsmasq.d-available/lxc as per the dnsmasq docs or manpage
– Ian Macintosh
Aug 19 '15 at 22:21
2
See How to let built-in DHCP assign a static IP to LXC container based on name, not MAC address
– Ian Macintosh
Aug 19 '15 at 22:58
add a comment |
Since you are bridging, you need to set the IP addresses in the container only, and not on the host. The host should only have its own IP address(es).
add a comment |
I just did it the other day with Ubuntu 14.04. It is simple. You just have to edit the /etc/network/interfaces
file inside your container, and set this:
auto eth0
iface eth0 inet static
address $IP
netmask $NETMASK
gateway $GW
dns-nameservers $DNS
Replace every variable with the desired value.
You DON'T have to do anything else!
PS: Notice the space before some lines. It is mandatory.
this resulted in my container not booting anymore (ubuntu 14.04 server).. the answer from sebastianwagner works for me.
– Dominik Dorn
Jul 21 '14 at 10:37
add a comment |
I could set up correctly my lxc containers after following @Enrique Moreno Tent's answer, so I will explain what to do in more details in case you don't know how to set up the other items.
1. Access your LXC container via lxc-attach
command
Command:
$ lxc-attach -n YOUR-CONTAINER-NAME
2. See your current configurations with ifconfig
Command
root@mycontainer:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.3.160 netmask 255.255.255.0 broadcast 10.0.3.255
inet6 fe80::216:3eff:fec9:2fa0 prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:c9:2f:a0 txqueuelen 1000 (Ethernet)
RX packets 62 bytes 7142 (7.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 60 bytes 9788 (9.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 20285 bytes 175021803 (175.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20285 bytes 175021803 (175.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
3. Getting address, netmask and gateway
Seeing the result of the ifconfig
command above, we then see:
Address is the address you want, you can change it to 10.0.3.166.
Netmask is there: 255.255.255.0
Gateway: For the gateway you use the broadcast address with here is 10.0.3.255
As you can see above, you currently have all information you need to fill your guest (container) /etc/network/interfaces
.
4. Getting dns-nameservers
value.
Issue the command:
cat /etc/resolv.conf
But maybe is best using Google DNS, which asre 8.8.8.8
and 8.8.4.4
5. Editing /etc/network/interfaces
INSIDE THE CONTAINER
auto eth0
iface eth0 inet static
address 10.0.3.166
netmask 255.255.255.0
gateway 10.0.3.255
dns-nameservers 8.8.8.8
ifconfig
has been replaced withip a
in more recent debian/ubuntu versions linuxconfig.org/…
– rvazquezglez
Jun 19 '18 at 4:27
add a comment |
The best way I find and the quickest is to use the lxc profiles
lxc profile list
- command the list all the profiles you have
Then
lxc profile copy default minecraft
(this is the name of your new profile)
Then lxc profile edit minecraft
This will come up
devices:
eth0:
ipv4.address: 192.168.1.114/24 - add this line and enter any ip address you like
name: eth0
nictype: macvlan - this is my setting
parent: enp0s25
type: nic
root:
path: /
pool: lxc_zfs
type: disk
name: mine
used_by:
then save it
next assign the profile to your LXC container like this
lxc profile assign YOUR_CONTAINER_NAME YOUR_NEW_PROFILE_NAME
then just restart the container and your new ip address is set to that container
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f571714%2fsetting-up-bridged-lxc-containers-with-static-ips%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
In fact you can set the address and gateway from within the host and configure the container not to touch the interface at all using the keyword manual
.
Place this within the guests /etc/network/interfaces
:
auto eth0
iface eth0 inet manual
Also leave it up to the container's config file to set up the interface:
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxc-bridge-nat
lxc.network.ipv4 = 192.168.100.16/24
lxc.network.ipv4.gateway = auto
The guest will behave like it's BIOS already set up the interface and just use it.
Especially explore lxc.network.ipv4.gateway
.
Thx! This saved my life... my container would always try to get a new dhcp address... setting it to a fixed value inside the container (static) resulted in the container not even booting anymore!
– Dominik Dorn
Jul 21 '14 at 10:36
Note that this doesn't work well if the host is suspended and resumed. The lxc continues with its allocated ip-address but the host thinks it doesn't have an ip-address anymore. I have found it is better to configure the dnsmasq for lxc-net and handout a fixed address there.
– HRJ
Aug 19 '14 at 12:40
@HRJ - You should include the 'how' in your comment or link to the ref rather than just saying 'do it'. This is a technical site and you should say something actually useable.
– Ian Macintosh
Aug 19 '15 at 22:14
2
It seems like the correct place to do this is both in /etc/default/lxc where you can set your range (see LXC_DHCP_RANGE) and in /etc/dnsmasq.d-available/lxc as per the dnsmasq docs or manpage
– Ian Macintosh
Aug 19 '15 at 22:21
2
See How to let built-in DHCP assign a static IP to LXC container based on name, not MAC address
– Ian Macintosh
Aug 19 '15 at 22:58
add a comment |
In fact you can set the address and gateway from within the host and configure the container not to touch the interface at all using the keyword manual
.
Place this within the guests /etc/network/interfaces
:
auto eth0
iface eth0 inet manual
Also leave it up to the container's config file to set up the interface:
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxc-bridge-nat
lxc.network.ipv4 = 192.168.100.16/24
lxc.network.ipv4.gateway = auto
The guest will behave like it's BIOS already set up the interface and just use it.
Especially explore lxc.network.ipv4.gateway
.
Thx! This saved my life... my container would always try to get a new dhcp address... setting it to a fixed value inside the container (static) resulted in the container not even booting anymore!
– Dominik Dorn
Jul 21 '14 at 10:36
Note that this doesn't work well if the host is suspended and resumed. The lxc continues with its allocated ip-address but the host thinks it doesn't have an ip-address anymore. I have found it is better to configure the dnsmasq for lxc-net and handout a fixed address there.
– HRJ
Aug 19 '14 at 12:40
@HRJ - You should include the 'how' in your comment or link to the ref rather than just saying 'do it'. This is a technical site and you should say something actually useable.
– Ian Macintosh
Aug 19 '15 at 22:14
2
It seems like the correct place to do this is both in /etc/default/lxc where you can set your range (see LXC_DHCP_RANGE) and in /etc/dnsmasq.d-available/lxc as per the dnsmasq docs or manpage
– Ian Macintosh
Aug 19 '15 at 22:21
2
See How to let built-in DHCP assign a static IP to LXC container based on name, not MAC address
– Ian Macintosh
Aug 19 '15 at 22:58
add a comment |
In fact you can set the address and gateway from within the host and configure the container not to touch the interface at all using the keyword manual
.
Place this within the guests /etc/network/interfaces
:
auto eth0
iface eth0 inet manual
Also leave it up to the container's config file to set up the interface:
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxc-bridge-nat
lxc.network.ipv4 = 192.168.100.16/24
lxc.network.ipv4.gateway = auto
The guest will behave like it's BIOS already set up the interface and just use it.
Especially explore lxc.network.ipv4.gateway
.
In fact you can set the address and gateway from within the host and configure the container not to touch the interface at all using the keyword manual
.
Place this within the guests /etc/network/interfaces
:
auto eth0
iface eth0 inet manual
Also leave it up to the container's config file to set up the interface:
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxc-bridge-nat
lxc.network.ipv4 = 192.168.100.16/24
lxc.network.ipv4.gateway = auto
The guest will behave like it's BIOS already set up the interface and just use it.
Especially explore lxc.network.ipv4.gateway
.
edited Jul 12 '17 at 2:55
atfornes
1034
1034
answered Apr 3 '14 at 23:50
sebastianwagnersebastianwagner
28622
28622
Thx! This saved my life... my container would always try to get a new dhcp address... setting it to a fixed value inside the container (static) resulted in the container not even booting anymore!
– Dominik Dorn
Jul 21 '14 at 10:36
Note that this doesn't work well if the host is suspended and resumed. The lxc continues with its allocated ip-address but the host thinks it doesn't have an ip-address anymore. I have found it is better to configure the dnsmasq for lxc-net and handout a fixed address there.
– HRJ
Aug 19 '14 at 12:40
@HRJ - You should include the 'how' in your comment or link to the ref rather than just saying 'do it'. This is a technical site and you should say something actually useable.
– Ian Macintosh
Aug 19 '15 at 22:14
2
It seems like the correct place to do this is both in /etc/default/lxc where you can set your range (see LXC_DHCP_RANGE) and in /etc/dnsmasq.d-available/lxc as per the dnsmasq docs or manpage
– Ian Macintosh
Aug 19 '15 at 22:21
2
See How to let built-in DHCP assign a static IP to LXC container based on name, not MAC address
– Ian Macintosh
Aug 19 '15 at 22:58
add a comment |
Thx! This saved my life... my container would always try to get a new dhcp address... setting it to a fixed value inside the container (static) resulted in the container not even booting anymore!
– Dominik Dorn
Jul 21 '14 at 10:36
Note that this doesn't work well if the host is suspended and resumed. The lxc continues with its allocated ip-address but the host thinks it doesn't have an ip-address anymore. I have found it is better to configure the dnsmasq for lxc-net and handout a fixed address there.
– HRJ
Aug 19 '14 at 12:40
@HRJ - You should include the 'how' in your comment or link to the ref rather than just saying 'do it'. This is a technical site and you should say something actually useable.
– Ian Macintosh
Aug 19 '15 at 22:14
2
It seems like the correct place to do this is both in /etc/default/lxc where you can set your range (see LXC_DHCP_RANGE) and in /etc/dnsmasq.d-available/lxc as per the dnsmasq docs or manpage
– Ian Macintosh
Aug 19 '15 at 22:21
2
See How to let built-in DHCP assign a static IP to LXC container based on name, not MAC address
– Ian Macintosh
Aug 19 '15 at 22:58
Thx! This saved my life... my container would always try to get a new dhcp address... setting it to a fixed value inside the container (static) resulted in the container not even booting anymore!
– Dominik Dorn
Jul 21 '14 at 10:36
Thx! This saved my life... my container would always try to get a new dhcp address... setting it to a fixed value inside the container (static) resulted in the container not even booting anymore!
– Dominik Dorn
Jul 21 '14 at 10:36
Note that this doesn't work well if the host is suspended and resumed. The lxc continues with its allocated ip-address but the host thinks it doesn't have an ip-address anymore. I have found it is better to configure the dnsmasq for lxc-net and handout a fixed address there.
– HRJ
Aug 19 '14 at 12:40
Note that this doesn't work well if the host is suspended and resumed. The lxc continues with its allocated ip-address but the host thinks it doesn't have an ip-address anymore. I have found it is better to configure the dnsmasq for lxc-net and handout a fixed address there.
– HRJ
Aug 19 '14 at 12:40
@HRJ - You should include the 'how' in your comment or link to the ref rather than just saying 'do it'. This is a technical site and you should say something actually useable.
– Ian Macintosh
Aug 19 '15 at 22:14
@HRJ - You should include the 'how' in your comment or link to the ref rather than just saying 'do it'. This is a technical site and you should say something actually useable.
– Ian Macintosh
Aug 19 '15 at 22:14
2
2
It seems like the correct place to do this is both in /etc/default/lxc where you can set your range (see LXC_DHCP_RANGE) and in /etc/dnsmasq.d-available/lxc as per the dnsmasq docs or manpage
– Ian Macintosh
Aug 19 '15 at 22:21
It seems like the correct place to do this is both in /etc/default/lxc where you can set your range (see LXC_DHCP_RANGE) and in /etc/dnsmasq.d-available/lxc as per the dnsmasq docs or manpage
– Ian Macintosh
Aug 19 '15 at 22:21
2
2
See How to let built-in DHCP assign a static IP to LXC container based on name, not MAC address
– Ian Macintosh
Aug 19 '15 at 22:58
See How to let built-in DHCP assign a static IP to LXC container based on name, not MAC address
– Ian Macintosh
Aug 19 '15 at 22:58
add a comment |
Since you are bridging, you need to set the IP addresses in the container only, and not on the host. The host should only have its own IP address(es).
add a comment |
Since you are bridging, you need to set the IP addresses in the container only, and not on the host. The host should only have its own IP address(es).
add a comment |
Since you are bridging, you need to set the IP addresses in the container only, and not on the host. The host should only have its own IP address(es).
Since you are bridging, you need to set the IP addresses in the container only, and not on the host. The host should only have its own IP address(es).
answered Feb 2 '14 at 22:42
Michael Hampton♦Michael Hampton
178k27326659
178k27326659
add a comment |
add a comment |
I just did it the other day with Ubuntu 14.04. It is simple. You just have to edit the /etc/network/interfaces
file inside your container, and set this:
auto eth0
iface eth0 inet static
address $IP
netmask $NETMASK
gateway $GW
dns-nameservers $DNS
Replace every variable with the desired value.
You DON'T have to do anything else!
PS: Notice the space before some lines. It is mandatory.
this resulted in my container not booting anymore (ubuntu 14.04 server).. the answer from sebastianwagner works for me.
– Dominik Dorn
Jul 21 '14 at 10:37
add a comment |
I just did it the other day with Ubuntu 14.04. It is simple. You just have to edit the /etc/network/interfaces
file inside your container, and set this:
auto eth0
iface eth0 inet static
address $IP
netmask $NETMASK
gateway $GW
dns-nameservers $DNS
Replace every variable with the desired value.
You DON'T have to do anything else!
PS: Notice the space before some lines. It is mandatory.
this resulted in my container not booting anymore (ubuntu 14.04 server).. the answer from sebastianwagner works for me.
– Dominik Dorn
Jul 21 '14 at 10:37
add a comment |
I just did it the other day with Ubuntu 14.04. It is simple. You just have to edit the /etc/network/interfaces
file inside your container, and set this:
auto eth0
iface eth0 inet static
address $IP
netmask $NETMASK
gateway $GW
dns-nameservers $DNS
Replace every variable with the desired value.
You DON'T have to do anything else!
PS: Notice the space before some lines. It is mandatory.
I just did it the other day with Ubuntu 14.04. It is simple. You just have to edit the /etc/network/interfaces
file inside your container, and set this:
auto eth0
iface eth0 inet static
address $IP
netmask $NETMASK
gateway $GW
dns-nameservers $DNS
Replace every variable with the desired value.
You DON'T have to do anything else!
PS: Notice the space before some lines. It is mandatory.
answered Jun 14 '14 at 17:27
Enrique Moreno TentEnrique Moreno Tent
2491417
2491417
this resulted in my container not booting anymore (ubuntu 14.04 server).. the answer from sebastianwagner works for me.
– Dominik Dorn
Jul 21 '14 at 10:37
add a comment |
this resulted in my container not booting anymore (ubuntu 14.04 server).. the answer from sebastianwagner works for me.
– Dominik Dorn
Jul 21 '14 at 10:37
this resulted in my container not booting anymore (ubuntu 14.04 server).. the answer from sebastianwagner works for me.
– Dominik Dorn
Jul 21 '14 at 10:37
this resulted in my container not booting anymore (ubuntu 14.04 server).. the answer from sebastianwagner works for me.
– Dominik Dorn
Jul 21 '14 at 10:37
add a comment |
I could set up correctly my lxc containers after following @Enrique Moreno Tent's answer, so I will explain what to do in more details in case you don't know how to set up the other items.
1. Access your LXC container via lxc-attach
command
Command:
$ lxc-attach -n YOUR-CONTAINER-NAME
2. See your current configurations with ifconfig
Command
root@mycontainer:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.3.160 netmask 255.255.255.0 broadcast 10.0.3.255
inet6 fe80::216:3eff:fec9:2fa0 prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:c9:2f:a0 txqueuelen 1000 (Ethernet)
RX packets 62 bytes 7142 (7.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 60 bytes 9788 (9.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 20285 bytes 175021803 (175.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20285 bytes 175021803 (175.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
3. Getting address, netmask and gateway
Seeing the result of the ifconfig
command above, we then see:
Address is the address you want, you can change it to 10.0.3.166.
Netmask is there: 255.255.255.0
Gateway: For the gateway you use the broadcast address with here is 10.0.3.255
As you can see above, you currently have all information you need to fill your guest (container) /etc/network/interfaces
.
4. Getting dns-nameservers
value.
Issue the command:
cat /etc/resolv.conf
But maybe is best using Google DNS, which asre 8.8.8.8
and 8.8.4.4
5. Editing /etc/network/interfaces
INSIDE THE CONTAINER
auto eth0
iface eth0 inet static
address 10.0.3.166
netmask 255.255.255.0
gateway 10.0.3.255
dns-nameservers 8.8.8.8
ifconfig
has been replaced withip a
in more recent debian/ubuntu versions linuxconfig.org/…
– rvazquezglez
Jun 19 '18 at 4:27
add a comment |
I could set up correctly my lxc containers after following @Enrique Moreno Tent's answer, so I will explain what to do in more details in case you don't know how to set up the other items.
1. Access your LXC container via lxc-attach
command
Command:
$ lxc-attach -n YOUR-CONTAINER-NAME
2. See your current configurations with ifconfig
Command
root@mycontainer:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.3.160 netmask 255.255.255.0 broadcast 10.0.3.255
inet6 fe80::216:3eff:fec9:2fa0 prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:c9:2f:a0 txqueuelen 1000 (Ethernet)
RX packets 62 bytes 7142 (7.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 60 bytes 9788 (9.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 20285 bytes 175021803 (175.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20285 bytes 175021803 (175.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
3. Getting address, netmask and gateway
Seeing the result of the ifconfig
command above, we then see:
Address is the address you want, you can change it to 10.0.3.166.
Netmask is there: 255.255.255.0
Gateway: For the gateway you use the broadcast address with here is 10.0.3.255
As you can see above, you currently have all information you need to fill your guest (container) /etc/network/interfaces
.
4. Getting dns-nameservers
value.
Issue the command:
cat /etc/resolv.conf
But maybe is best using Google DNS, which asre 8.8.8.8
and 8.8.4.4
5. Editing /etc/network/interfaces
INSIDE THE CONTAINER
auto eth0
iface eth0 inet static
address 10.0.3.166
netmask 255.255.255.0
gateway 10.0.3.255
dns-nameservers 8.8.8.8
ifconfig
has been replaced withip a
in more recent debian/ubuntu versions linuxconfig.org/…
– rvazquezglez
Jun 19 '18 at 4:27
add a comment |
I could set up correctly my lxc containers after following @Enrique Moreno Tent's answer, so I will explain what to do in more details in case you don't know how to set up the other items.
1. Access your LXC container via lxc-attach
command
Command:
$ lxc-attach -n YOUR-CONTAINER-NAME
2. See your current configurations with ifconfig
Command
root@mycontainer:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.3.160 netmask 255.255.255.0 broadcast 10.0.3.255
inet6 fe80::216:3eff:fec9:2fa0 prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:c9:2f:a0 txqueuelen 1000 (Ethernet)
RX packets 62 bytes 7142 (7.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 60 bytes 9788 (9.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 20285 bytes 175021803 (175.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20285 bytes 175021803 (175.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
3. Getting address, netmask and gateway
Seeing the result of the ifconfig
command above, we then see:
Address is the address you want, you can change it to 10.0.3.166.
Netmask is there: 255.255.255.0
Gateway: For the gateway you use the broadcast address with here is 10.0.3.255
As you can see above, you currently have all information you need to fill your guest (container) /etc/network/interfaces
.
4. Getting dns-nameservers
value.
Issue the command:
cat /etc/resolv.conf
But maybe is best using Google DNS, which asre 8.8.8.8
and 8.8.4.4
5. Editing /etc/network/interfaces
INSIDE THE CONTAINER
auto eth0
iface eth0 inet static
address 10.0.3.166
netmask 255.255.255.0
gateway 10.0.3.255
dns-nameservers 8.8.8.8
I could set up correctly my lxc containers after following @Enrique Moreno Tent's answer, so I will explain what to do in more details in case you don't know how to set up the other items.
1. Access your LXC container via lxc-attach
command
Command:
$ lxc-attach -n YOUR-CONTAINER-NAME
2. See your current configurations with ifconfig
Command
root@mycontainer:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.3.160 netmask 255.255.255.0 broadcast 10.0.3.255
inet6 fe80::216:3eff:fec9:2fa0 prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:c9:2f:a0 txqueuelen 1000 (Ethernet)
RX packets 62 bytes 7142 (7.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 60 bytes 9788 (9.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 20285 bytes 175021803 (175.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20285 bytes 175021803 (175.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
3. Getting address, netmask and gateway
Seeing the result of the ifconfig
command above, we then see:
Address is the address you want, you can change it to 10.0.3.166.
Netmask is there: 255.255.255.0
Gateway: For the gateway you use the broadcast address with here is 10.0.3.255
As you can see above, you currently have all information you need to fill your guest (container) /etc/network/interfaces
.
4. Getting dns-nameservers
value.
Issue the command:
cat /etc/resolv.conf
But maybe is best using Google DNS, which asre 8.8.8.8
and 8.8.4.4
5. Editing /etc/network/interfaces
INSIDE THE CONTAINER
auto eth0
iface eth0 inet static
address 10.0.3.166
netmask 255.255.255.0
gateway 10.0.3.255
dns-nameservers 8.8.8.8
edited Jan 5 '17 at 21:03
answered Jan 2 '17 at 16:31
IacchusIacchus
1113
1113
ifconfig
has been replaced withip a
in more recent debian/ubuntu versions linuxconfig.org/…
– rvazquezglez
Jun 19 '18 at 4:27
add a comment |
ifconfig
has been replaced withip a
in more recent debian/ubuntu versions linuxconfig.org/…
– rvazquezglez
Jun 19 '18 at 4:27
ifconfig
has been replaced with ip a
in more recent debian/ubuntu versions linuxconfig.org/…– rvazquezglez
Jun 19 '18 at 4:27
ifconfig
has been replaced with ip a
in more recent debian/ubuntu versions linuxconfig.org/…– rvazquezglez
Jun 19 '18 at 4:27
add a comment |
The best way I find and the quickest is to use the lxc profiles
lxc profile list
- command the list all the profiles you have
Then
lxc profile copy default minecraft
(this is the name of your new profile)
Then lxc profile edit minecraft
This will come up
devices:
eth0:
ipv4.address: 192.168.1.114/24 - add this line and enter any ip address you like
name: eth0
nictype: macvlan - this is my setting
parent: enp0s25
type: nic
root:
path: /
pool: lxc_zfs
type: disk
name: mine
used_by:
then save it
next assign the profile to your LXC container like this
lxc profile assign YOUR_CONTAINER_NAME YOUR_NEW_PROFILE_NAME
then just restart the container and your new ip address is set to that container
add a comment |
The best way I find and the quickest is to use the lxc profiles
lxc profile list
- command the list all the profiles you have
Then
lxc profile copy default minecraft
(this is the name of your new profile)
Then lxc profile edit minecraft
This will come up
devices:
eth0:
ipv4.address: 192.168.1.114/24 - add this line and enter any ip address you like
name: eth0
nictype: macvlan - this is my setting
parent: enp0s25
type: nic
root:
path: /
pool: lxc_zfs
type: disk
name: mine
used_by:
then save it
next assign the profile to your LXC container like this
lxc profile assign YOUR_CONTAINER_NAME YOUR_NEW_PROFILE_NAME
then just restart the container and your new ip address is set to that container
add a comment |
The best way I find and the quickest is to use the lxc profiles
lxc profile list
- command the list all the profiles you have
Then
lxc profile copy default minecraft
(this is the name of your new profile)
Then lxc profile edit minecraft
This will come up
devices:
eth0:
ipv4.address: 192.168.1.114/24 - add this line and enter any ip address you like
name: eth0
nictype: macvlan - this is my setting
parent: enp0s25
type: nic
root:
path: /
pool: lxc_zfs
type: disk
name: mine
used_by:
then save it
next assign the profile to your LXC container like this
lxc profile assign YOUR_CONTAINER_NAME YOUR_NEW_PROFILE_NAME
then just restart the container and your new ip address is set to that container
The best way I find and the quickest is to use the lxc profiles
lxc profile list
- command the list all the profiles you have
Then
lxc profile copy default minecraft
(this is the name of your new profile)
Then lxc profile edit minecraft
This will come up
devices:
eth0:
ipv4.address: 192.168.1.114/24 - add this line and enter any ip address you like
name: eth0
nictype: macvlan - this is my setting
parent: enp0s25
type: nic
root:
path: /
pool: lxc_zfs
type: disk
name: mine
used_by:
then save it
next assign the profile to your LXC container like this
lxc profile assign YOUR_CONTAINER_NAME YOUR_NEW_PROFILE_NAME
then just restart the container and your new ip address is set to that container
answered May 17 at 23:39
JayferretJayferret
111
111
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f571714%2fsetting-up-bridged-lxc-containers-with-static-ips%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown