Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is the neat way of organizing files in /etc/network/interfaces.d ?

3 views
Skip to first unread message

Stella Ashburne

unread,
May 15, 2022, 7:40:05 PM5/15/22
to
Hi guys

I connect to the internet using one of the following methods:

1. LAN cable
2. Tethering to a mobile phone using a USB cable
3. Wireless (4 different wireless networks)

Based on the result of

ip addr show

my wireless interface is called wlo1

The contents of /etc/network/interfaces are

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
#auto lo
#iface lo inet loopback

There are three files in /etc/network/interfaces.d/ depending on how I connect to the internet. They are:

a. lan
b. usb0
c. wlo1

The contents of lan are:

# The primary network interface (connect to internet using a LAN cable)
allow-hotplug enx6
iface enx6 inet static
address 192.168.1.38/24
gateway 192.168.1.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 1.1.1.1 8.8.8.8



The contents of usb0 are:

# The primary network interface (tethering to mobile phone using a USB cable)
allow-hotplug usb0
iface usb0 inet dhcp
address 192.168.30.70
gateway 192.168.30.129
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 1.1.1.1 8.8.8.8



The contents of wlo1 are:

# The primary network interface (connect to wireless network #1)
#allow-hotplug wlo1
#iface wlo1 inet dhcp
# wpa-ssid wireless-network-1
# wpa-psk {string of alphanumeric characters}
# address 192.168.22.85
# gateway 192.168.22.1
# dns-nameservers 1.1.1.1 8.8.8.8

# The primary network interface (connect to wireless network #2)
allow-hotplug wlo1
iface wlo1 inet dhcp
wpa-ssid wireless-network-2
wpa-psk {string of alphanumeric characters}
address 192.168.15.27
gateway 192.168.15.1
dns-nameservers 1.1.1.1 8.8.8.8

# The primary network interface (connect to wireless network #3)
#allow-hotplug wlo1
#iface wlo1 inet dhcp
# wpa-ssid wireless-network-3
# wpa-psk {string of alphanumeric characters}
# address 192.168.51.45
# gateway 192.168.51.1
# dns-nameservers 1.1.1.1 8.8.8.8

# The primary network interface (connect to wireless network #4)
#allow-hotplug wlo1
#iface wlo1 inet dhcp
# wpa-ssid wireless-network-4
# wpa-psk {string of alphanumeric characters}
# address 192.168.70.31
# gateway 192.168.70.1
# dns-nameservers 1.1.1.1 8.8.8.8



For example when I wish to connect to wireless-network-3, I ensure that all the lines after

# The primary network interface (connect to wireless network #2)

commented with a #

And I remove the # from all the lines after

# The primary network interface (connect to wireless network #3)

I save the changes and type the commands:

sudo ifdown wlo1 && sudo ifup wlo1


Questions

I. Depending on how I connect to the internet, I create a file each called lan, usb0 and wlo1 and place them in /etc/network/interfaces.d. Is there a neater way of doing it?

2. In the file called wlo1, I have four parts that correspond to the four different wireless networks. is there a neater way of doing it?

Best regards.

Stella

Charles Curley

unread,
May 15, 2022, 9:40:05 PM5/15/22
to
On Mon, 16 May 2022 01:10:20 +0200
Stella Ashburne <rew...@gmx.com> wrote:

> I. Depending on how I connect to the internet, I create a file each
> called lan, usb0 and wlo1 and place them in
> /etc/network/interfaces.d. Is there a neater way of doing it?

Network Manager.

If you insist on writing your own script, it should be feasible. Maybe
a case statement based on the SSID the access point provides?

>
> 2. In the file called wlo1, I have four parts that correspond to the
> four different wireless networks. is there a neater way of doing it?

If you use Network Manager, get rid of wlo1 and any other files for
interfaces other than lo. I don't know if NM will manage a USB
interface, though.

If you insist on writing your own scripts, I'd use a case statement
based on the SSID and an appropriate HERE statement for each interface.
Have those go to a file under /etc/network.

--
Does anybody read signatures any more?

https://charlescurley.com
https://charlescurley.com/blog/

David Wright

unread,
May 15, 2022, 11:50:04 PM5/15/22
to
On Mon 16 May 2022 at 01:10:20 (+0200), Stella Ashburne wrote:

> 2. In the file called wlo1, I have four parts that correspond to the four different wireless networks. is there a neater way of doing it?

Yes. Put each wlo1 configuration into a separate file called either:
wlo1-nw1, wlo1-nw2, wlo1-nw3, wlo1-nw4
or, more sensibly:
wlo1-nw22, wlo1-nw15, wlo1-nw51, wlo1-nw70
removing the # from all the non-comment lines.

You now have six files: lan, usb0, wlo1-nw22, wlo1-nw15, wlo1-nw51, wlo1-nw70,
which you can handle in a similar manner to however you presently
select between your three files.

You could manually (de)activate any file's definition with
ifup or ifdown.

Alternatively, you could move the ones you want activated into
/etc/network/interfaces.d/, and move the ones that you don't
somewhere else, like /etc/network/unused-interfaces/.

The point of this being to avoid having to /edit/ files in order
to change networks. Keep the files' contents fixed, and vary
the selection of files to be read. It's much less error-prone.

Cheers,
David.

Stella Ashburne

unread,
May 16, 2022, 6:50:04 AM5/16/22
to
Mon cher

Thanks for your reply.

> Sent: Monday, May 16, 2022 at 9:33 AM
> From: "Charles Curley" <charle...@charlescurley.com>
> To: "Debian Users" <debia...@lists.debian.org>
> Subject: Re: What is the neat way of organizing files in /etc/network/interfaces.d ?
>
> Network Manager.
>
No thank you. I won't touch it with a ten-foot pole.

> If you insist on writing your own script, it should be feasible. Maybe
> a case statement based on the SSID the access point provides?
>
>
> If you insist on writing your own scripts, I'd use a case statement
> based on the SSID and an appropriate HERE statement for each interface.
> Have those go to a file under /etc/network.
>
My technical knowledge limits me to writing the scripts that you mentioned.

Would it be possible for you to show me a sample/specimen?

Best regards.

Stella

Stella Ashburne

unread,
May 16, 2022, 7:10:05 AM5/16/22
to
Mon cher

It's been quite a while since I heard from you. I hope everything's well with you and your family!

> Sent: Monday, May 16, 2022 at 11:42 AM
> From: "David Wright" <deb...@lionunicorn.co.uk>
> To: debia...@lists.debian.org
> Subject: Re: What is the neat way of organizing files in /etc/network/interfaces.d ?
>
>
> You now have six files: lan, usb0, wlo1-nw22, wlo1-nw15, wlo1-nw51, wlo1-nw70,
> which you can handle in a similar manner to however you presently
> select between your three files.
>
What did you mean? What are the three files?

> You could manually (de)activate any file's definition with
> ifup or ifdown.
>
Could you elaborate please?

Did you mean that in a terminal, I type

sudo ifdown wl01-nw22

or

sudo ifup wlo1-nw22

> Alternatively, you could move the ones you want activated into
> /etc/network/interfaces.d/, and move the ones that you don't
> somewhere else, like /etc/network/unused-interfaces/.
>
That seems to be a good idea.

So I moved wlo1-nw15, wlo1-nw51 and wlo1-nw70 to /etc/network/unused-interfaces/ leaving only wl01-nw22 in /etc/network/interfaces.d

However, when I typed the following in a termminal

sudo ifdown wlo1-nw22

The error was

ifdown: interface not configured

or

ifdown: unknown interface

The output of

ip addr show

show that my wireless interface is called wl01

I appreciate your help.

Best regards.

Stella

Greg Wooledge

unread,
May 16, 2022, 7:20:05 AM5/16/22
to
On Mon, May 16, 2022 at 01:03:27PM +0200, Stella Ashburne wrote:
> So I moved wlo1-nw15, wlo1-nw51 and wlo1-nw70 to /etc/network/unused-interfaces/ leaving only wl01-nw22 in /etc/network/interfaces.d
>
> However, when I typed the following in a termminal
>
> sudo ifdown wlo1-nw22
> ifdown: interface not configured

You've misspelled it. You have wl01-nw22 versus wlo1-nw22 (zero versus
lowercase oh).

> ip addr show
>
> show that my wireless interface is called wl01

A third name? You'd better take the time to figure out which of these
three names is the correct one.

Stella Ashburne

unread,
May 16, 2022, 8:20:05 AM5/16/22
to
You're right, mon cher.

My typos have indeed led to confusion and they're inexcusable. Mea culpa....

> Sent: Monday, May 16, 2022 at 7:15 PM
> From: "Greg Wooledge" <gr...@wooledge.org>
> To: debia...@lists.debian.org
> Subject: Re: What is the neat way of organizing files in /etc/network/interfaces.d ?
>
> You've misspelled it. You have wl01-nw22 versus wlo1-nw22 (zero versus
> lowercase oh).
>
Indeed, I should've checked my post for typos before I sent it. Mea maxima culpa....

wlo1-nw22 is the correct one. (the letter o is wedged between the letter l and the number 1)

> > ip addr show
> >
> > show that my wireless interface is called wl01
>
> A third name? You'd better take the time to figure out which of these
> three names is the correct one.
>
wlo1 is the correct one. (the letter o is wedged between the letter l and the number 1)

P.S.: To David Wright - Please take note of the above. I'm sorry for the errors.

Charles Curley

unread,
May 16, 2022, 11:30:08 AM5/16/22
to
On Sun, 15 May 2022 22:42:26 -0500
David Wright <deb...@lionunicorn.co.uk> wrote:

> Alternatively, you could move the ones you want activated into
> /etc/network/interfaces.d/, and move the ones that you don't
> somewhere else, like /etc/network/unused-interfaces/.

Or put them all in /etc/network/unused-interfaces/, and manage the lot
with symlinks in /etc/network/interfaces.d/.

David Wright

unread,
May 16, 2022, 11:50:05 AM5/16/22
to
On Mon 16 May 2022 at 13:03:27 (+0200), Stella Ashburne wrote:
> > Sent: Monday, May 16, 2022 at 11:42 AM
> > From: "David Wright" <deb...@lionunicorn.co.uk>
> >
> > You now have six files: lan, usb0, wlo1-nw22, wlo1-nw15, wlo1-nw51, wlo1-nw70,
> > which you can handle in a similar manner to however you presently
> > select between your three files.
> >
> What did you mean? What are the three files?

I think you need to find a friend and show them your post,
which lists three files, and then my reply. Get them to
show you how the paragraphs in my reply correspond with
the various parts of your post.

> However, when I typed the following in a termminal
>
> sudo ifdown wlo1-nw22
>
> The error was
>
> ifdown: interface not configured
>
> or
>
> ifdown: unknown interface
>
> The output of
>
> ip addr show
>
> show that my wireless interface is called wl01

Yes, your friend could probably explain the difference between
an interface name contained in a file, and the filename itself.

Cheers,
David.

David Wright

unread,
May 16, 2022, 12:00:05 PM5/16/22
to
On Mon 16 May 2022 at 09:26:22 (-0600), Charles Curley wrote:
> On Sun, 15 May 2022 22:42:26 -0500 David Wright wrote:
>
> > Alternatively, you could move the ones you want activated into
> > /etc/network/interfaces.d/, and move the ones that you don't
> > somewhere else, like /etc/network/unused-interfaces/.
>
> Or put them all in /etc/network/[un]used-interfaces/, and manage the lot
> with symlinks in /etc/network/interfaces.d/.

(Aside: I was trying to reduce the number of alternatives suggested.
This is mostly a repeat of Feb/Mar's thread "What should I put inside
the file called wlan0?". Each suggestion will morph into yet another
subthread.)

Cheers,
David.

Stella Ashburne

unread,
May 16, 2022, 12:00:06 PM5/16/22
to
Mon cher

> Sent: Monday, May 16, 2022 at 11:26 PM
> From: "Charles Curley" <charle...@charlescurley.com>
> To: "Debian Users" <debia...@lists.debian.org>
> Subject: Re: What is the neat way of organizing files in /etc/network/interfaces.d ?
>
>
> Or put them all in /etc/network/unused-interfaces/, and manage the lot
> with symlinks in /etc/network/interfaces.d/.
>
I don't quite get your idea.

Can you illustrate your suggestion with an example please? Thanks.

Best regards.

Stella

Tim Woodall

unread,
May 17, 2022, 1:30:04 AM5/17/22
to
On Mon, 16 May 2022, Stella Ashburne wrote:

> Hi guys
>
> I connect to the internet using one of the following methods:
>

It's really hard to understand what you're wanting to do.

option 1.

Use a mapping

You have "interfaces" like
wlo1-doozy
wlo1-home
wlo1-cafe

And a script whose job is to return one of them.

ifup wlo1 will then start whichever one the script returns.



option 2.

Have a script that creates/deletes the files for you for the setup you
want.


option 3

Have a script that manipulates symlinks instead of the files.


option 4

Continue editing files like you are.


option 5

buy N identical computers and label them wlo1-doozy etc, use the
appropriate one.



option 7

go with something like network manager



Handling variable network setup is never easy. People want it to be
automagical but 'get it right' and often those things can be in
conflict. I use a mapping script, but the cost is that I have to do some
manual updates every time I want to connect to a new access point. Where
there's a portal I have to jump through more hoops.

The advantage of my setup is that I can connect to a particular AP which
is useful for debugging my home network where I have multiple AP that
overlap but (occasionally) one gets into a tizzy and 'normal' software
refuses to connect to the weaker but working one so I can reboot the
other broken one. (most people would just turn it off and on again but I
like a chance to look at logs first.)
0 new messages