Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set gateway to each interface? #3

Open
HuJK opened this issue Aug 31, 2018 · 3 comments
Open

How to set gateway to each interface? #3

HuJK opened this issue Aug 31, 2018 · 3 comments

Comments

@HuJK
Copy link

HuJK commented Aug 31, 2018

I want to set gateway in conf

if I set

ip route change default nexthop via 192.168.0.254 dev eth1 weight 1 nexthop via 192.168.11.50 dev eth2 weight 1

pingu will remove all my route settings.

But if I set gateway=192.168.0.254
I will get error like this:

/etc/pingu/pingu.conf: Unknown keyword 'gateway' (line 19)
@typecampo
Copy link

typecampo commented Aug 31, 2018

Not sure if this helps but I found that running pingu -v removes the routes when sopping it with ctrl+c. However, when I do service pingu start/stop the routes remain.

@HuJK
Copy link
Author

HuJK commented Sep 3, 2018

This is what I am doing:

##Initial condition: alpine in docker with CAP_NET_ADMIN
##and connected 3 networks. 
apk add iproute2 pingu
ifconfig
#(3 interface returned. eth0 eth1 eth2)
#(eth0 is internal , eth1 is interface1 with macvlan, eth2 is interface2 with macvlan)

##enable NAT
sysctl net.ipv4.ip_forward=1
iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -j MASQUERADE

##set gateway                         ↓gateway1↓                                  ↓gateway2↓
ip route change default nexthop via 192.168.0.254 dev eth1 weight 1 nexthop via 192.168.11.50 dev eth2 weight 1
#Now I can get internet access, package will randomly choose eth1 or eth2 to send


ip route list
#default
#        nexthop via 192.168.0.254 dev eth1 weight 1
#        nexthop via 192.168.11.50 dev eth2 weight 1
#172.18.0.0/24 dev eth0 proto kernel scope link src 172.18.0.4
#192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.2
#192.168.11.0/24 dev eth2 proto kernel scope link src 192.168.11.3

vi /etc/pingu/pingu.conf
#interval        30
#retry           5
#required        3
#timeout         1.0
#interface eth1 {
#        label           ISP via eth1
#        rule-priority 20000
#        required-hosts-online   1
#        load-balance
#}
#
#interface eth2 {
#        label           ISP via eth2
#        rule-priority 20000
#        required-hosts-online   1
#        load-balance
#}
#host 8.8.8.8 {
#        label           Google public DNS (via eth1)
#        bind-interface  eth1
#        bind-interface  eth2
#}

##start pingu
pingu
#pingu[49]: New interface: eth1
#pingu[49]: eth1: got link
#pingu[49]: New interface: eth2
#pingu[49]: eth2: got link
#pingu[49]: New route to 192.168.0.0/24 dev eth1 metric 0 table 2
#pingu[49]: New route to 192.168.11.0/24 dev eth2 metric 0 table 1
#pingu[49]: Google public DNS (via eth1): went OFFLINE
#pingu[49]: 8.8.4.4: went OFFLINE
#pingu[49]: ISP via eth2: went OFFLINE
#pingu[49]: 8.8.4.4: went OFFLINE
#pingu[49]: ISP via eth1: went OFFLINE
######Now I can no longer access the internet##########
ip route list
#172.18.0.0/24 dev eth0 proto kernel scope link src 172.18.0.4
#192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.2
#192.168.11.0/24 dev eth2 proto kernel scope link src 192.168.11.3
##getway record has been removed

Any step I do is wrong?

@typecampo
Copy link

I have not played with the loud-balance option. Im only wanting pingu to switch between the two if one goes down (will be handled with gateway up/down action in pingu.conf).

Here is what I have in my interfaces file:
`auto eth1
iface eth1 inet static
address 10.11.10.100
netmask 255.255.0.0
gateway 10.11.0.1
post-up ip route add 10.11.0.0/16 dev eth1 table 11
post-up ip route add default via 10.11.0.1 dev eth1 table 11
post-up ip rule add priority 11 from 10.11.10.100 table 11
post-up ip rule add priority 12 to 10.11.10.100 table 11
post-down ip rule del priority 11 from 10.11.10.100 table 11
post-down ip rule del priority 12 to 10.11.10.100 table 11

auto eth2
iface eth2 inet static
address 10.14.10.100
netmask 255.255.0.0
post-up ip route add 10.14.0.0/16 dev eth2 table 21
post-up ip route add default via 10.14.0.1 dev eth2 table 21
post-up ip rule add priority 21 from 10.14.10.100 table 21
post-up ip rule add priority 22 to 10.14.10.100 table 21
post-down ip rule del priority 21 from 10.14.10.100 table 21
post-down ip rule del priority 22 to 10.14.10.100 table 21
`
interface eth1 {
label VSAT1 via eth1
route-table 11
rule-priority 11
required-hosts-online 1
ping 8.8.4.4
}

interface eth2 {
label VSAT2 via eth2
route-table 21
rule-priority 21
required-hosts-online 1
ping 8.8.8.8
}

If you notice, the route-table and rule-priority match the table I use in the interfaces file. This way the routes persist and no new route is added or removed when pingu starts or stops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants