Docker and pipework,ip with other subnet


 
Thread Tools Search this Thread
Operating Systems Linux Docker and pipework,ip with other subnet
# 1  
Old 06-29-2015
Docker and pipework,ip with other subnet

Recently i found this for give to docker a "personal" ip

Code:
    ip addr del 10.1.1.133/24 dev eth0
    ip link add link eth0 dev eth0m type macvlan mode bridge
    ip link set eth0m up
    ip addr add 10.1.1.133/24 dev eth0m
    route add default gw 10.1.1.1

On container i did

Code:
    CID=$(docker run -d ...)
    pipework eth0 $CID 10.1.1.133/24@10.1.1.1

This works fine if host and docker containers all are on same subnet(10.1.1.0/24 in this case)
But if i want to use a different subnet for dockers?
For example 10.2.2.0/24?

I have tried a iptables masquerade,but nothing works,the docker container cannot ping or reach external network(internet).


Code:
    iptables -t nat -A POSTROUTING -m iprange --src-range 10.2.2.2-10.2.2.255 -o eth0 -j MASQUERADE

Of course ip forwarding is enabled

---------- Post updated 29-06-15 at 05:40 PM ---------- Previous update was 28-06-15 at 10:02 PM ----------

Solution found.
The host must setup as router,enable iptables NAT and enable route to new ip class,in this case eth0m is the bridged network

Code:
    iptables -A FORWARD -i eth0m -o eth0m -j ACCEPT
    iptables -A FORWARD -i eth0m -o eth0m  -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
    iptables -t nat  -A POSTROUTING -o eth0m -j MASQUERADE

pipework must use the new router,in this case is 192.168.0.254

Code:
    pipework eth0 $DOCKID 10.8.3.1/24@192.168.0.254

and finally route must be added,in this case 10.8.3.0 is the other ip class

Code:
    route add -net 10.8.3.0 netmask 255.255.255.0  dev eth0m


Last edited by Linusolaradm1; 06-29-2015 at 07:51 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Docker

Docker learning Phase-I

Hello All, I had recently learnt a bit of Docker(which provides containerization process). Here are some of my learning points from it. Let us start first with very basic question: What is Docker: Docker is a platform for sysadmins and developers to DEPLOY, DEVELOP and RUN applications ... (7 Replies)
Discussion started by: RavinderSingh13
7 Replies

2. UNIX for Beginners Questions & Answers

Can't pass a variable representing the output of lsb_release to a docker dontainer

I don't know why, but the rendering of my code mucks up the spacing and indentation, despite being correct in the original file. I'm having issues getting the following script to run (specifically the nested script at the end of the docker command near the end of the script; I think I'm not passing... (2 Replies)
Discussion started by: James Ray
2 Replies

3. Shell Programming and Scripting

Problem in extracting yocto SDK for docker

Actually I was facing the following issue while building my Yocto SDK on Docker container sudo docker build --tag="akash/eclipse-che:6.5.0-1" --tag="akash/eclipse-che:latest" /home/akash/dockerimage.yocto.support/ Sending build context to Docker daemon 26.93MB Step 1/5 : FROM eclipse/cpp_gcc ... (3 Replies)
Discussion started by: Akash BHardwaj
3 Replies

4. IP Networking

2 ip from one subnet my isp

Hi. my english is not so good. sorry. i have some problem. My isp give me second ip from subnet. One network is working, but secong don't. fxp0 - my network dc0 - network isp (that working) re0 - network isp (don't working) i try use ng_one2many, but it's don't working ngctl mkpeer... (0 Replies)
Discussion started by: kil
0 Replies

5. IP Networking

How many hosts per subnet

What would be a realistic number of hosts in a 100BaseT network, before you have to start thinking on subnetting further? Or in another words. How many hosts would you keep in the same broadcast domain? In a 100BaseT network, with subnet 10.20.20.0/24, I could have 254 hosts as part of the same... (3 Replies)
Discussion started by: Aia
3 Replies

6. IP Networking

How do I figure out the subnet?

Hi, How do I get subnet from this: 10.252.0.138/25 Tnx (2 Replies)
Discussion started by: mehrdad68
2 Replies

7. IP Networking

Migrating existing Subnet to a new subnet and changing ip addresses in UNIX

Hi, My project needs to migrate the existing Subnet (255.255.255.0) to a new subnet and change the ipaddresses (currently C class). How can I do that. I need some information. John (0 Replies)
Discussion started by: johnmarsh
0 Replies

8. UNIX for Advanced & Expert Users

Two Ethernet Connections to Same Subnet

Hi Gurus, I have a Sun Box ( Sun OS 5.5.1 ) running with two Fast Ethernet PCI cards ( instance hme1 and hme2 ), apart from the onboard Ethernet connection. These two Ethernets are connected to the same subnet. Now, will there be any automated load balancing due to these two Ethernet... (1 Reply)
Discussion started by: shibz
1 Replies

9. IP Networking

Subnet mask

Hi, I have about 30 computers for users with subnet mask x.x.x.0, and 25 computers for workers with s.m. x.x.x.128. My server has a s.m. x.x.x.128 so with workers computers I can see my server and all the computers in that s.m., but I can't see the server from the users computers and I need to see... (7 Replies)
Discussion started by: Z0DiaC
7 Replies
Login or Register to Ask a Question