Internet connection with a DHCP on my Oracle Linux LXC 7.3

This article explains how to sign a physical network interface to an Oracle Linux Containers 7.3  LXC using the Oracle Linux 7.x as Host, while creating an interface network with a DHCP network address.

Plan:

  1. Creation of an Oracle Linux Container LXC 7u3
  2. Sign a physical network inteface to an Oracle Linux container LXC 7u3
  3. Test Internet connection from my LXC

1. Creation of an Oracle Linux LXC container:

My Host machine is an Oracle Linux 7.3 (x86_64) with 3 network interfaces, while the NIC 3 will be signed to my Oracle Linux Container LXC 7u3.

Host Container: Oracle Linux 7.3 (hostname: ol7u3-lxc01 )

Gest LXC : Oracle Linux 7.3 (hostname: ol7u3-db12c)

a. Activation of NIC N°3 using Oracle VirtualBox.

– Using the NAT network (DHCP configuration). (I want my LXC to connect to internet)

MAC Address:  08:00:27:73:89:ac

b. Check the network interface on the Host Oracle Linux 7.3.

[root@ol7u3-lxc01 ~] # ifconfig enp0s9
enp0s9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 08:00:27:73:89:ac  txqueuelen 1000  (Ethernet)
        RX packets 17  bytes 1587 (1.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

c. Creation of an Oracle Linux Container 7.3

I have written an article step by step to create an Oracle Linux Container LXC 7.3 on Oracle Linux 7.3

 

2. Sign a physical network inteface to an Oracle Linux container LXC 7u3:

 

a. Modify the configuration file of the container LXC.

I have mapped my Oracle Linux LXC with my NIC while the MAC address is 08:00:27:73:89:ac

[root@ol7u3-lxc01 ~]# cat /container/ol7u3-db12c.wadhahdaouehi.tn/config
# Template used to create this container: /usr/share/lxc/templates/lxc-oracle
# Parameters passed to the template: --release=7.3
# For additional config options, please look at lxc.container.conf(5)
lxc.network.type = phys
lxc.network.link = enp0s9
lxc.network.flags = up
lxc.network.hwaddr = 08:00:27:73:89:ac
lxc.network.name = eth0
lxc.network.mtu = 1500
lxc.rootfs = /container/ol7u3-db12c.wadhahdaouehi.tn/rootfs
# Common configuration
lxc.include = /usr/share/lxc/config/oracle.common.conf
# Container configuration for Oracle Linux 7.3
lxc.arch = x86_64
lxc.utsname = ol7u3-db12c.wadhahdaouehi.tn
lxc.cap.drop = sys_resource

b. Start the Oracle Linux LXC:

[root@ol7u3-lxc01 ~]# lxc-start -n ol7u3-db12c.wadhahdaouehi.tn

c. Connect to the LXC Oracle Linux:

[root@ol7u3-lxc01 ~]# lxc-attach -n ol7u3-db12c.wadhahdaouehi.tn

d. Check the network configuration:

[root@ol7u3-db12c ~]# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:73:89:ac brd ff:ff:ff:ff:ff:ff
    inet 10.0.4.15/24 brd 10.0.4.255 scope global dynamic eth0
       valid_lft 86393sec preferred_lft 86393sec
    inet6 fe80::a00:27ff:fe73:89ac/64 scope link
       valid_lft forever preferred_lft forever


[root@ol7u3-db12c ~]# ip route
default via 10.0.4.2 dev eth0
10.0.4.0/24 dev eth0  proto kernel  scope link  src 10.0.4.15

3. Test Internet connection from my LXC:

[root@ol7u3-db12c ~]# ping google.tn
PING google.tn (216.58.205.195) 56(84) bytes of data.
64 bytes from mil04s29-in-f3.1e100.net (216.58.205.195): icmp_seq=1 ttl=49 time=87.7 ms
64 bytes from mil04s29-in-f3.1e100.net (216.58.205.195): icmp_seq=2 ttl=49 time=85.9 ms
64 bytes from mil04s29-in-f3.1e100.net (216.58.205.195): icmp_seq=3 ttl=49 time=103 ms
^C
--- google.tn ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 85.943/92.517/103.841/8.045 ms

 

Note: After my Oracle Linux LXC connected to internet using the physical NIC moreover my NIC will not be managed by my Host Oracle Linux container.

[root@ol7u3-lxc01 ~]# ifconfig enp0s9
enp0s9: error fetching interface information: Device not found

 

Conclusion:

Oracle Linux LXC 7.3 connect to internet connection using a DHCP address while mapped to physical network.

 

Bookmark the permalink.
Loading Facebook Comments ...

Leave a Reply