I want to change the network device name eth0 to eth1. What should I do? What configuration files should I modify?
Sorry, this is a bit long, but it is worth explaining for people searching on how to rename devices (not just the ethernet).
Renaming devices is the realm of “udev”. Information on that topic will be the same on any Linux platform. Normally the system has a series of unmodified udev rules in one of these locations:
/lib/udev/rules.d/
/lib/systemd/system/
There is also a place where one can override these:
/etc/udev/rules.d/
/etc/systemd/system/
If the “/etc/” location is empty, then all of the “/lib/” defaults are used directly.
If you put a file from the “/lib/” version within the “/etc/” location (same file name), then you are essentially doing nothing if the files match. If you then edit the “/etc/” version, then this will override the system version until (a) the edit is reverted, or (b) the file is removed from “/etc/”.
Often there will be a generic name for some service or device, and then a symbolic link made to the specific version to be used (for example, initial text mode or GUI mode is normally “multi-user.target” or “graphical.target”, but the file controlling it would have a name like “default.target”, and this would always be a symbolic link pointing at multi-user.target or graphical.target, so on. In other cases a file is directly copied into a “/etc/” location from a “/lib/” version because it is to be customized. Network device naming is one such possibility.
There are various types of rules with inheritance, but you are interested in “rules”. Other pieces of the systemd files will name rules to be used, but you only need to modify a rule for that particular hardware and the system should pick this up. The rule would be modified in “/etc/”, possibly by starting with a copy of a similar file in “/lib/”.
A word of warning: Often network devices are named via their MAC address. You would use “ifconfig” to find this ("ifconfig | egrep ‘HWaddr .*$’). If this were cloned to another Jetson, then the MAC address would be incorrect for the other Jetson.
An interesting way to see some possibilities (you may need to sudo for some steps):
egrep -R 'ATTR[{]address[}]' /lib/systemd 2>/dev/null
egrep -R 'ATTR[{]address[}]' /lib/udev 2>/dev/null
egrep -R 'ATTR[{]address[}]' /etc/udev 2>/dev/null
egrep -R 'ATTR[{]address[}]' /etc/systemd/system 2>/dev/null
The “2>/dev/null” is to hide errors from dangling symbolic links.
The default naming convention is eth#, but on some systems it might read something like enp4s6…when the default naming doesn’t exist, then it is due to a udev rule. When you do not see a rule for the specific device then it means the naming was never overridden. In that case you will need to write a rule from scratch. You could try this…create file “/etc/udev/rules.d/70-persistent-net.rules”. For the content:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="<u><i><b>00:00:00:00:00:00</b></i></u>",ATTR{dev_id}=="0x0", ATTR{type}=="1",
KERNEL=="eth0", NAME="eth1"
…but edit the MAC address, use the one matching your original eth0.
After the MAC address edit see if this works.
Currently, the network device name naming convention starts with eth0 and the next device name is eth1.But now I want to start with eth1, and the next network device name is eth2.Other than that, I don’t want to think about MAC addresses, let the system automatically identify them.What should I do?
What you want is easy if you are willing to name a specific device, but in terms of a general renaming scheme I have to do some research. Udev would be the way to do this, and the rule file would look similar to the current default rules, but with some edits. Since the rules are default I don’t see the exact rule file to edit. I’m asking some people who know more about this than I do…when I find out more I’ll post here.
Meanwhile, consider that you can experiment safely by copying any existing file from “/lib/udev/rules.d/” into “/etc/udev/rules.d/” and testing out an edit. If you think you’ve found the correct rule to use as a template it is reasonably safe to try it out in “/etc”.