[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Under each of these scenarios, what is the neatest and simplest way to manipulate the /etc/network/interfaces file?



On Sat 19 Mar 2022 at 03:14:54 (+0100), Stella Ashburne wrote:
> 
> There are instances in which my machine is connected to a mobile hotspot. And in some situations, it's connected to a smartphone via USB tethering. And when I'm in the office, I may connect it to a LAN cable.
> 
> Below are the contents of my /etc/network/interfaces file:
> 
> # 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/*

I would change this line to

source-directory /etc/network/interfaces.d

(which was the default on new buster installations).

I would then hive off all your interface configurations into
separate files in the directory /etc/network/interfaces.d
using all-ASCII filenames constructed from upper/lower-case
letters, digits, underscores, and minus-hyphens, as specified
on the man page, but with the string ".hidden" added to the end,
thus:

myphone-tethered.hidden
office-wired.hidden
wifi.hidden
hotspot.hidden

and so on. Files with a dot are ignored when included by means of
a source-directory directive.

> 1. At the moment, if I wish to change to using a mobile hotspot from USB tethering, I'll edit the /etc/network/interfaces file, uncomment the applicable lines under #The primary network interface for wireless connections and place a # in front of all the lines under #The primary network interface for USB tethering
> 
> Instead of carrying out the above steps, is there a neater and simpler way?

Editing a file each time you make a change is error-prone.
To use any one of the interfaces with this mechanism, all
you have to do now is rename the file, removing the .hidden:

# mv -i /etc/network/interfaces.d/wifi.hidden /etc/network/interfaces.d/wifi

and that becomes the active one because there's no dot. (The
word "hidden" is my semantic sugar.) Vice versa to deactivate.

> 2. What is the command to type in a terminal after I have made changes to the /etc/network/interfaces file without rebooting my machine?

# ifdown en……      (ie down the old interface)

# …                (rename the files as explained above)

# ifup wl……        (up the new interface)

The thing to remember (and so many don't) is that the /e/n/i
files are retaining the active network configuration, and
need to be kept in place until you have downed the interface.
Only /then/ should you make changes to the files.

Don't do what works with many other daemons, which is to change
the configuration files first, and then try to "restart" networking:
ifdown followed by ifup. That confuses it.

Cheers,
David.


Reply to: