Two or more network interfaces: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 18: | Line 18: | ||
* Add | * Add | ||
<pre> | <pre> | ||
if /sbin/ip -4 route show | grep -wq "n.n.n.n/ | if /sbin/ip -4 route show | grep -wq "n.n.n.n/n dev ethX"; then | ||
/sbin/ip -4 route del n.n.n.n/ | /sbin/ip -4 route del n.n.n.n/n dev ethX | ||
fi | fi | ||
if ! /sbin/ip -4 route show table rt1 | grep -wq "n.n.n.n/ | if ! /sbin/ip -4 route show table rt1 | grep -wq "n.n.n.n/n dev ethX"; then | ||
/sbin/ip -4 route add n.n.n.n/ | /sbin/ip -4 route add n.n.n.n/n dev ethX scope link src a.a.a.a table rt1 | ||
fi | fi | ||
if ! /sbin/ip -4 route show table rt1 | grep -wq default; then | if ! /sbin/ip -4 route show table rt1 | grep -wq default; then | ||
| Line 36: | Line 36: | ||
* Add | * Add | ||
<pre> | <pre> | ||
if /sbin/ip -4 route show table rt1 | grep -wq "n.n.n.n/ | if /sbin/ip -4 route show table rt1 | grep -wq "n.n.n.n/n dev ethX"; then | ||
/sbin/ip -4 route del n.n.n.n/ | /sbin/ip -4 route del n.n.n.n/n dev ethX table rt1 | ||
fi | fi | ||
if /sbin/ip -4 route show table rt1 | grep -wq default; then | if /sbin/ip -4 route show table rt1 | grep -wq default; then | ||
Revision as of 01:11, 8 December 2023
Suppose that we have an additional network interface ethX with a network n.n.n.n/n, an ip address a.a.a.a, and a gateway g.g.g.g.
- Add a routing table to
/etc/iproute2/rt_tables:
# # reserved values # 255 local 254 main 253 default 0 unspec # # local # #1 inr.ruhep 1 rt1
- Add
if /sbin/ip -4 route show | grep -wq "n.n.n.n/n dev ethX"; then /sbin/ip -4 route del n.n.n.n/n dev ethX fi if ! /sbin/ip -4 route show table rt1 | grep -wq "n.n.n.n/n dev ethX"; then /sbin/ip -4 route add n.n.n.n/n dev ethX scope link src a.a.a.a table rt1 fi if ! /sbin/ip -4 route show table rt1 | grep -wq default; then /sbin/ip -4 route add default via g.g.g.g dev ethX table rt1 fi if ! /sbin/ip -4 rule show | grep -wq "lookup rt1"; then /sbin/ip -4 rule add from a.a.a.a/32 table rt2 /sbin/ip -4 rule add to a.a.a.a/32 table rt2 fi
to the end of IPv4 section of the function gateway_up in /etc/rc.d/rc.inet1
- Add
if /sbin/ip -4 route show table rt1 | grep -wq "n.n.n.n/n dev ethX"; then /sbin/ip -4 route del n.n.n.n/n dev ethX table rt1 fi if /sbin/ip -4 route show table rt1 | grep -wq default; then /sbin/ip -4 route del default table rt1 fi if /sbin/ip -4 rule show | grep -wq "lookup rt1"; then /sbin/ip -4 rule del from a.a.a.a/32 table rt1 /sbin/ip -4 rule del to a.a.a.a/32 table rt1 fi
to the end of IPv4 section of the function gateway_down in /etc/rc.d/rc.inet1
- # /etc/rc.d/rc.inet1 restart