User avatar
XueHai8
Posts: 70
Joined: Mon Jul 24, 2017 12:19 pm

Stretch: Non-existent network names on boot for iptables

Wed Aug 23, 2017 6:16 am

How to assign network names in iptables on boot when they don't exist yet?

Here's an example:

Code: Select all

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Set to execute at boot under /etc/rc.local - Hahahahahah - not under Stretch
Network adapter names don't exist when rc.local is run, so this don't work either to get the new bizzarro network names:

Code: Select all

ip -o link show | awk '{print $2,$9}' | grep 'UP'| awk -F: '{print $1}
So how can I code an iptables bash script, that needs to run at boot time, to get a network name that doesn't even exist until sometime after the Pi boots - and that is portable to another Pi?
I'm getting S-T-R-E-T-C-H marks from this release...

User avatar
rpdom
Posts: 17170
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Stretch: Non-existent network names on boot for iptables

Wed Aug 23, 2017 6:32 am

Stretch has a new feature called "Predictable Interface Names" or something like that. It has been around for over a year on other Debian based systems like Ubuntu. It uses the mac address of the interface to generate a name instead of calling the first interface it finds eth0 and the second eth1, as this could change depending on what is detected during boot.

It is a pain.

If you want to disable it and go back to the old method you can edit /boot/cmdline.txt and add net.ifnames=0 to the end of the line.

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Stretch: Non-existent network names on boot for iptables

Wed Aug 23, 2017 11:52 am

rpdom wrote:
Wed Aug 23, 2017 6:32 am

It is a pain.
It is NOT a pain, it's just a unannounced, incompatible change that the RPF folks failed to notice, failed to highlight and failed to ensure that it didn't cause unexpected problems.

As soon as you have a linux system with more than one network interface it's much better to build a network name using the MAC addresss. Arch Linux has had that support for a very long time.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

hippy
Posts: 7728
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Stretch: Non-existent network names on boot for iptables

Wed Aug 23, 2017 12:37 pm

If I recall correctly, even with Jessie, there were issues relating to the state of the network and information about it when placing code in rc.local. I believe that's why 'wait for network' was added as an option.

That and 'predictable naming' appears to have come about through adoption of systemd, and compounded here by the way the Foundation has decided to implement networking.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Stretch: Non-existent network names on boot for iptables

Wed Aug 23, 2017 1:15 pm

don't use rc.local use a systemd service file for this sort of stuff...
fixing names is different [see above]
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
XueHai8
Posts: 70
Joined: Mon Jul 24, 2017 12:19 pm

Re: Stretch: Non-existent network names on boot for iptables

Thu Aug 24, 2017 12:56 am

Thank you all for your responses, but I think my main question was missed:
So how can I code an iptables bash script, that needs to run at boot time, to get a network name that doesn't even exist until sometime after the Pi boots - and that is portable to another Pi?

With Wait for Network enabled, which I have done, where do I auto start my scripts to get network names?

Even putting them in cron with @reboot doesn't work.

+Disabling it doesn't work for Wireless adapters.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Stretch: Non-existent network names on boot for iptables

Thu Aug 24, 2017 10:54 am

add
net.ifnames=0
to the end of cmdline.txt
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
XueHai8
Posts: 70
Joined: Mon Jul 24, 2017 12:19 pm

Re: Stretch: Non-existent network names on boot for iptables

Sat Aug 26, 2017 1:48 am

adding net.ifnames=0 only postpones the inevitable of having to deal with this new naming (un)convention. Plus, as I stated earlier, it does not work on wireless adapters.

Return to “Troubleshooting”