SlideShare a Scribd company logo
Moving your routing
inside container
Marian Marinov <mm@siteground.com>
I'm running 2 routers inside
containers for the past 2 years
Marian Marinov <mm@siteground.com>
Disclaimer:
- my home router have 3 ISPs, two of which with BGP
sessions and I have my own /24 and /56 prefixes
- my office routers have at least two ISPs, BGP and
their own v4 and v6 prefixes
Marian Marinov <mm@siteground.com>
Why would you move your router inside a container?
● Isolating the routing from the other parts of the
system
● Solving problems with non-routed IPs
● Solving problems with wrong outgoing addresses
on multihomed routers
● Simplifying your firewall setup
Marian Marinov <mm@siteground.com>
If your routing table is similar to this:
# ip route show
default via 12.63.16.1 dev eth0
12.63.16.0/24 dev eth0 proto kernel scope link
src 12.63.16.99
127.0.0.0/8 dev lo scope link
Marian Marinov <mm@siteground.com>
If your routing table is similar to this:
# ip route show
default via 12.63.16.1 dev eth0
12.63.16.0/24 dev eth0 proto kernel scope link
src 12.63.16.99
127.0.0.0/8 dev lo scope link
You don't have any problems :)
Marian Marinov <mm@siteground.com>
But the moment you get two or more ISPs,
you get something like this:
root@hydra:~# ip rule list
0: from all lookup local
32761: from 77.104.187.0/24 lookup telepoint
32762: from 194.12.255.42 lookup evolink
32763: from 91.139.184.0/22 lookup bulsat
32764: from 46.40.126.131 lookup bulsat
32765: from 78.142.5.137 lookup bulsat
32766: from all lookup main
32767: from all lookup default
Marian Marinov <mm@siteground.com>
At that point, the problems start to show up:
● Services such as DNS servers choose the
wrong outgoing IP when making outgoing
connections
● Simple commands like ping require
parameters to get the correct result
Marian Marinov <mm@siteground.com>
At that point, the problems start to show up:
● Services such as DNS servers choose the
wrong outgoing IP when making outgoing
connections
● Simple commands like ping require
parameters to get the correct result
Marian Marinov <mm@siteground.com>
Moving the router inside its own container
solves this!
By separating the actual routing from the rest
of the services, all services now choose the
correct(working) routes
Now your DNS and/or VPN can not, by accident,
select the wrong source IPs.
Marian Marinov <mm@siteground.com>
So what exactly means to move your router
inside a container?
Marian Marinov <mm@siteground.com>
Let's say you have a machine with 3 Ethernet
cards:
eth0 - your home/office network
eth1 - ISP1
eth2 - ISP2
Marian Marinov <mm@siteground.com>
What you need to do is:
1. create a new netns
# ip netns add router
2. create a veth pair between the host and the new netns
# ip link add veth0 type veth peer name veth1
# ip link set veth1 netns router
# ip netns exec router ip link set veth1 name eth3
3. move all eth devices to the router netns(this will drop the
connectivity)
# for i in {0..2}; do 
ip link set eth$i netns router; done
4. setup the IP addresses inside the new netns
5. setup the routing
Marian Marinov <mm@siteground.com>
Now, all traffic that should go trough the VPN
should be routed via eth3 and also your
services, such as DNS should be routed via
eth3.
The firewall becomes much simpler for the
services and for the router, as it is now split
and you would never hit the problems with non-
routable IPs
Marian Marinov <mm@siteground.com>
If you want to put your BGP inside the new
netns, you simply have to start your BGP
daemon(Quagga, Bird, OpenBGPd) inside the
new netns:
# ip netns exec router /bin/bash
# bird
Marian Marinov <mm@siteground.com>

More Related Content

DOCX
Packet tracer practical guide
PDF
designandimplementanetwork
PDF
Student packet tracer manual v1.1
DOCX
CCNA Packet Tracer 1.6.1
PPTX
How to make a simple application on packet tracer
DOCX
Telnet configuration
PPT
Packet tracer
PPTX
Networking
Packet tracer practical guide
designandimplementanetwork
Student packet tracer manual v1.1
CCNA Packet Tracer 1.6.1
How to make a simple application on packet tracer
Telnet configuration
Packet tracer
Networking

What's hot (20)

PDF
4.1.2.9 packet tracer documenting the network instructions
PPSX
Packet Tracer Tutorial # 1
PDF
Ccna cheat sheet
PDF
Step by Step guide to set up a simple network in Packet Tracer
PDF
Wan configuration in packet tracer by Tanjilur Rahman
PPT
Chapter11ccna
PPTX
M3 – cisco packet tracer lab
PDF
NAT- Network Address Translation
PDF
Access list-cheatsheet
PDF
Ccna new lab_manual_by_esp_team
PDF
Computer Networking Lab File
DOC
Simple network troubleshooting
PDF
CCNA CheatSheet
PPT
PDF
119163798 icnd1-practice-questions-9tut
PPT
CCNA Router and IOS Basics
PDF
Pt using packettracer
PDF
Ccnav5.org ccna 1-v50_itn_practice_final_exam_answers
DOCX
Examen ccna capitulo 6 en ingles
4.1.2.9 packet tracer documenting the network instructions
Packet Tracer Tutorial # 1
Ccna cheat sheet
Step by Step guide to set up a simple network in Packet Tracer
Wan configuration in packet tracer by Tanjilur Rahman
Chapter11ccna
M3 – cisco packet tracer lab
NAT- Network Address Translation
Access list-cheatsheet
Ccna new lab_manual_by_esp_team
Computer Networking Lab File
Simple network troubleshooting
CCNA CheatSheet
119163798 icnd1-practice-questions-9tut
CCNA Router and IOS Basics
Pt using packettracer
Ccnav5.org ccna 1-v50_itn_practice_final_exam_answers
Examen ccna capitulo 6 en ingles
Ad

Viewers also liked (20)

PDF
Protecting your home and office in the era of IoT
ODP
Securing the network for VMs or Containers
PDF
Io t introduction to electronics
ODP
Computer vision for your projects
PDF
Lxd the proper way of runing containers
PDF
Practical my sql performance optimization
PDF
How penetration testing techniques can help you improve your qa skills
ODP
How to setup your linux server
PDF
Make your internship "worth it"
PPTX
LUG-BG - Kostadin Slavkov - PostgreSQL 10
ODP
Home assistant
ODP
Protecting your data when entering the US
PDF
Introduction to python
PDF
Gluster.community.day.2013
PDF
Why we are migrating to Slackware
PDF
LUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFS
PDF
4 Sessions
PDF
Comparison of foss distributed storage
PDF
Performance comparison of Distributed File Systems on 1Gbit networks
ODP
nftables - the evolution of Linux Firewall
Protecting your home and office in the era of IoT
Securing the network for VMs or Containers
Io t introduction to electronics
Computer vision for your projects
Lxd the proper way of runing containers
Practical my sql performance optimization
How penetration testing techniques can help you improve your qa skills
How to setup your linux server
Make your internship "worth it"
LUG-BG - Kostadin Slavkov - PostgreSQL 10
Home assistant
Protecting your data when entering the US
Introduction to python
Gluster.community.day.2013
Why we are migrating to Slackware
LUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFS
4 Sessions
Comparison of foss distributed storage
Performance comparison of Distributed File Systems on 1Gbit networks
nftables - the evolution of Linux Firewall
Ad

Similar to Moving your router inside container (20)

PPSX
Packet Tracer Tutorial # 2
PPTX
ASSIGNMENT PPT.pptx
PDF
Packet walks in_kubernetes-v4
PDF
Sharing your-internet-connection-on-linux
PPT
Design of a campus network
PDF
Good - aDocker - Reference Materials.pdf
PDF
CCNA - Routing & Switching Commands
PPTX
Introduction to tcp ip linux networking
PDF
Routing Information Protocol (RIP)
PPTX
Linux – routing and firewall for beginners v 1.0
PDF
Deeper Dive in Docker Overlay Networks
PDF
Cisco labs practical3
PPTX
Docker networking Tutorial 101
PDF
Cloud Monitors Cloud
PDF
Ccna Commands In 10 Minutes
PDF
Network commands
PDF
Docker Networking Deep Dive
PDF
Docker 1.12 networking deep dive
PPT
Linux networking
DOCX
Nat report2
Packet Tracer Tutorial # 2
ASSIGNMENT PPT.pptx
Packet walks in_kubernetes-v4
Sharing your-internet-connection-on-linux
Design of a campus network
Good - aDocker - Reference Materials.pdf
CCNA - Routing & Switching Commands
Introduction to tcp ip linux networking
Routing Information Protocol (RIP)
Linux – routing and firewall for beginners v 1.0
Deeper Dive in Docker Overlay Networks
Cisco labs practical3
Docker networking Tutorial 101
Cloud Monitors Cloud
Ccna Commands In 10 Minutes
Network commands
Docker Networking Deep Dive
Docker 1.12 networking deep dive
Linux networking
Nat report2

More from Marian Marinov (20)

PDF
How to start and then move forward in IT
PDF
Thinking about highly-available systems and their setup
PDF
Understanding your memory usage under Linux
PDF
How to implement PassKeys in your application
PDF
Dev.bg DevOps March 2024 Monitoring & Logging
PDF
Basic presentation of cryptography mechanisms
PDF
Microservices: Benefits, drawbacks and are they for me?
PDF
Introduction and replication to DragonflyDB
PDF
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
PDF
How to successfully migrate to DevOps .pdf
PDF
How to survive in the work from home era
PDF
Managing sysadmins
PDF
Improve your storage with bcachefs
PDF
Control your service resources with systemd
PDF
Comparison of-foss-distributed-storage
PDF
Защо и как да обогатяваме знанията си?
PDF
Securing your MySQL server
PDF
Sysadmin vs. dev ops
PDF
DoS and DDoS mitigations with eBPF, XDP and DPDK
PDF
Challenges with high density networks
How to start and then move forward in IT
Thinking about highly-available systems and their setup
Understanding your memory usage under Linux
How to implement PassKeys in your application
Dev.bg DevOps March 2024 Monitoring & Logging
Basic presentation of cryptography mechanisms
Microservices: Benefits, drawbacks and are they for me?
Introduction and replication to DragonflyDB
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
How to successfully migrate to DevOps .pdf
How to survive in the work from home era
Managing sysadmins
Improve your storage with bcachefs
Control your service resources with systemd
Comparison of-foss-distributed-storage
Защо и как да обогатяваме знанията си?
Securing your MySQL server
Sysadmin vs. dev ops
DoS and DDoS mitigations with eBPF, XDP and DPDK
Challenges with high density networks

Recently uploaded (20)

PDF
Digital Logic Computer Design lecture notes
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Construction Project Organization Group 2.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Sustainable Sites - Green Building Construction
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Welding lecture in detail for understanding
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
UNIT 4 Total Quality Management .pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Digital Logic Computer Design lecture notes
Lecture Notes Electrical Wiring System Components
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Construction Project Organization Group 2.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
R24 SURVEYING LAB MANUAL for civil enggi
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Sustainable Sites - Green Building Construction
Automation-in-Manufacturing-Chapter-Introduction.pdf
Welding lecture in detail for understanding
Foundation to blockchain - A guide to Blockchain Tech
Embodied AI: Ushering in the Next Era of Intelligent Systems
UNIT 4 Total Quality Management .pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf

Moving your router inside container

  • 1. Moving your routing inside container Marian Marinov <mm@siteground.com>
  • 2. I'm running 2 routers inside containers for the past 2 years Marian Marinov <mm@siteground.com>
  • 3. Disclaimer: - my home router have 3 ISPs, two of which with BGP sessions and I have my own /24 and /56 prefixes - my office routers have at least two ISPs, BGP and their own v4 and v6 prefixes Marian Marinov <mm@siteground.com>
  • 4. Why would you move your router inside a container? ● Isolating the routing from the other parts of the system ● Solving problems with non-routed IPs ● Solving problems with wrong outgoing addresses on multihomed routers ● Simplifying your firewall setup Marian Marinov <mm@siteground.com>
  • 5. If your routing table is similar to this: # ip route show default via 12.63.16.1 dev eth0 12.63.16.0/24 dev eth0 proto kernel scope link src 12.63.16.99 127.0.0.0/8 dev lo scope link Marian Marinov <mm@siteground.com>
  • 6. If your routing table is similar to this: # ip route show default via 12.63.16.1 dev eth0 12.63.16.0/24 dev eth0 proto kernel scope link src 12.63.16.99 127.0.0.0/8 dev lo scope link You don't have any problems :) Marian Marinov <mm@siteground.com>
  • 7. But the moment you get two or more ISPs, you get something like this: root@hydra:~# ip rule list 0: from all lookup local 32761: from 77.104.187.0/24 lookup telepoint 32762: from 194.12.255.42 lookup evolink 32763: from 91.139.184.0/22 lookup bulsat 32764: from 46.40.126.131 lookup bulsat 32765: from 78.142.5.137 lookup bulsat 32766: from all lookup main 32767: from all lookup default Marian Marinov <mm@siteground.com>
  • 8. At that point, the problems start to show up: ● Services such as DNS servers choose the wrong outgoing IP when making outgoing connections ● Simple commands like ping require parameters to get the correct result Marian Marinov <mm@siteground.com>
  • 9. At that point, the problems start to show up: ● Services such as DNS servers choose the wrong outgoing IP when making outgoing connections ● Simple commands like ping require parameters to get the correct result Marian Marinov <mm@siteground.com>
  • 10. Moving the router inside its own container solves this! By separating the actual routing from the rest of the services, all services now choose the correct(working) routes Now your DNS and/or VPN can not, by accident, select the wrong source IPs. Marian Marinov <mm@siteground.com>
  • 11. So what exactly means to move your router inside a container? Marian Marinov <mm@siteground.com>
  • 12. Let's say you have a machine with 3 Ethernet cards: eth0 - your home/office network eth1 - ISP1 eth2 - ISP2 Marian Marinov <mm@siteground.com>
  • 13. What you need to do is: 1. create a new netns # ip netns add router 2. create a veth pair between the host and the new netns # ip link add veth0 type veth peer name veth1 # ip link set veth1 netns router # ip netns exec router ip link set veth1 name eth3 3. move all eth devices to the router netns(this will drop the connectivity) # for i in {0..2}; do ip link set eth$i netns router; done 4. setup the IP addresses inside the new netns 5. setup the routing Marian Marinov <mm@siteground.com>
  • 14. Now, all traffic that should go trough the VPN should be routed via eth3 and also your services, such as DNS should be routed via eth3. The firewall becomes much simpler for the services and for the router, as it is now split and you would never hit the problems with non- routable IPs Marian Marinov <mm@siteground.com>
  • 15. If you want to put your BGP inside the new netns, you simply have to start your BGP daemon(Quagga, Bird, OpenBGPd) inside the new netns: # ip netns exec router /bin/bash # bird Marian Marinov <mm@siteground.com>