CumulusNetworks / ifupdown2

GNU General Public License v2.0
161 stars 75 forks source link

source additional file returns error #309

Closed jamiew0w closed 2 months ago

jamiew0w commented 3 months ago

hello.

i route a lot of ports and the interfaces file gets a bit unwieldy. i was testing with the source-directory because that'd make my life a lot easier (plus allow cool things like scripting symlinks to bring stuff up and down) but i've ran into issues very quickly.

network/interfaces: source-directory /etc/network/interfaces.d (tested with at the top and bottom of the file if that matters)

interfaces.d/test

  post-up   iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 5555 -j DNAT --to 10.0.0.121:5555
  post-down iptables -t nat -D PREROUTING -i eno1 -p tcp --dport 5555 -j DNAT --to 10.0.0.121:5555

error

error: /etc/network/interfaces.d/test: line1: error processing line 'post-up   iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 5555 -j DNAT --to 10.0.0.111:5555'

thing is, if i simply cat the rule and put it back in the interfaces file then reload, all is fine.

is this not supported via source-directory?

julienfortin commented 2 months ago

Hi @jamiew0w

The syntax needs to follow the /e/n/i format, meaning that you should put the post-up and post-down statement under a specific stanza

auto eno1
iface eno1
  post-up   iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 5555 -j DNAT --to 10.0.0.121:5555
  post-down iptables -t nat -D PREROUTING -i eno1 -p tcp --dport 5555 -j DNAT --to 10.0.0.121:5555
jamiew0w commented 2 months ago

Hi @jamiew0w

The syntax needs to follow the /e/n/i format, meaning that you should put the post-up and post-down statement under a specific stanza

auto eno1
iface eno1
  post-up   iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 5555 -j DNAT --to 10.0.0.121:5555
  post-down iptables -t nat -D PREROUTING -i eno1 -p tcp --dport 5555 -j DNAT --to 10.0.0.121:5555

Thank you! I'll go ahead and close this out, I really should have tried this before making an issue - my bad!