Skip to content

Commit c50d5c3

Browse files
committed
Merge branch 'master' of github.com:mstathers/stathers-net
2 parents 0e84e2b + 50874c0 commit c50d5c3

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
layout: posts
3+
title: NetworkManager - Source Policy Routing
4+
---
5+
6+
This can be considered a part two of a previous post on [source policy routing]({% post_url 2015-06-25-source-policy-routing %}). Review that post for an overview of source policy routing.
7+
8+
This post will demonstrate how to use [NetworkManager](https://networkmanager.dev/) to configure source policy routing. The main advantage of using NetworkManager is it's included with modern Enterprise Linux distributions and it handles boot time persistence.
9+
10+
## Network Diagram
11+
![Source Policy Routing - Network Diagram](/pictures/source_policy_netdia.png "Source Policy Routing - Network Diagram")
12+
13+
14+
## Instructions
15+
Start by creating two new tables, one for each interface.
16+
*/etc/iproute2/rt_tables*
17+
{% highlight text %}
18+
#
19+
# Reserved values
20+
#
21+
255 local
22+
254 main
23+
253 default
24+
0 unspec
25+
#
26+
# Dual-interface routing tables
27+
# - prinet: Private interface (eth0) routing table
28+
# - pubnet: Public interface (eth1) routing table
29+
#
30+
100 prinet
31+
101 pubnet
32+
{% endhighlight %}
33+
34+
Find the UUIDs of each connection. These UUIDs will be used to configure each connection.
35+
{% highlight bash %}
36+
$ nmcli --fields DEVICE,UUID connection show
37+
DEVICE UUID
38+
eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
39+
eth1 fd703f29-a874-37dc-948d-2b1a719e0d6f
40+
lo 2ff97c54-daca-42f6-a8fd-fc1bd74e2acb
41+
{% endhighlight %}
42+
43+
44+
## `eth0`
45+
Configure the routes and rules for the `eth0` interface. In this example, assume our default gateway will be out `eth0`.
46+
{% highlight bash %}
47+
$ eth0_uuid=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
48+
$ eth0_ip=10.10.0.5
49+
$ eth0_cidr=10.10.0.0/24
50+
$ eth0_gateway=10.10.0.254
51+
$ nmcli connection modify ${eth0_uuid} \
52+
+ipv4.routes '${eth0_ip}/32 0.0.0.0 0 table=100' \
53+
+ipv4.routes '0.0.0.0/0 ${eth0_gateway} 0 table=100' \
54+
+ipv4.routes '${eth0_cidr} 0.0.0.0 0' \
55+
+ipv4.routing-rules 'priority 100 from ${eth0_cidr} table 100'
56+
{% endhighlight %}
57+
58+
## `eth1`
59+
Configure the routes and rules for the `eth1` interface. Very similar to `eth0`, but disable the default gateway on this interface.
60+
{% highlight bash %}
61+
$ eth1_uuid=fd703f29-a874-37dc-948d-2b1a719e0d6f
62+
$ eth1_ip=10.20.0.5
63+
$ eth1_cidr=10.20.0.0/24
64+
$ eth1_gateway=10.20.0.254
65+
$ nmcli connection modify ${eth1_uuid} ipv4.never-default yes \
66+
+ipv4.routes '${eth1_ip}/32 0.0.0.0 0 table=101' \
67+
+ipv4.routes '0.0.0.0/0 ${eth1_gateway} 0 table=101' \
68+
+ipv4.routes '${eth1_cidr} 0.0.0.0 0' \
69+
+ipv4.routing-rules 'priority 101 from ${eth1_cidr} table 101'
70+
{% endhighlight %}
71+
72+
## Reload Connections
73+
74+
{% highlight bash %}
75+
nmcli connection up ${eth0_uuid}
76+
nmcli connection up ${eth1_uuid}
77+
{% endhighlight %}

0 commit comments

Comments
 (0)