LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2010, 11:10 PM   #1
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Rep: Reputation: 34
Alias eth0 to lan


I know I can rename my network interfaces (eg 'eth0' to 'lan', 'eth1' to 'net' etc) but does anyone know a way I can alias (symlink if you like) 'lan' -> 'eth0'

I want to be able to use more legible interface names in things like iptables rules (such as "-i lan" instead of "-i eth0") but I don't want to break any config that is expecting eth0 to exist....
 
Old 04-08-2010, 11:29 PM   #2
mweed
Member
 
Registered: Mar 2006
Posts: 33

Rep: Reputation: 17
Depending on your OS should be able to set this in udev.

in /etc/udev/rules.d grep for a file that has the eth definitions in it.

You should see a line like:
Code:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="99:99:99:02:0f:d2", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Edit that file and change eth0 to whatever you want to call it.

Do not forget to update your network configuration files for the new name. RedHat like distros in /etc/sysconfig/network-scripts

Other methods of renaming interfaces include ifrename along with /etc/iftab or using the ip command.

Technically this shouldn't break anything, but who knows what apps are out there expecting interfaces to be called eth[0-9].

Let us know how it works out.
 
Old 04-08-2010, 11:45 PM   #3
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
Traditionalists will use variable names that are meaningful and assign the actual eth0 or whatever values to them:

iptables=/sbin/iptables
internal_interface=eth0
internal_subnet=10.0.1.0/24


$iptables -A INPUT -i $internal_interface -s $internal_subnet ......

That way you get to keep the default names, you don't have to remember what jiggery pokery you went through to rename things, and nothing breaks.

Last edited by bakdong; 04-08-2010 at 11:46 PM. Reason: iptables is not in /usr/bin !
 
Old 04-09-2010, 12:18 AM   #4
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by mweed View Post
Depending on your OS should be able to set this in udev.
Sorry, should have mentioned I'm specifically using CentOS 5.4 in this instance.

Quote:
Originally Posted by mweed View Post
You should see a line like:
Code:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="99:99:99:02:0f:d2", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Edit that file and change eth0 to whatever you want to call it.
I don't want to change the current name, just create an alias/"symlink" from 'lan' to 'eth0'...

Quote:
Originally Posted by bakdong View Post
Traditionalists will use variable names that are meaningful and assign the actual eth0 or whatever values to them:
Yes, I could do that, but that means reinventing the iptables init script and discarding the stock one which I'd like to retain for simplicities sake (eg, when other sysadmins are on the box and don't know that it's actually "firewall" instead of "iptables" when calling service or chkconfig)... And I generally hate reinventing the wheel, especially for something as "small" as this
 
Old 04-09-2010, 02:48 AM   #5
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
Quote:
Originally Posted by fukawi2 View Post
Yes, I could do that, but that means reinventing the iptables init script and discarding the stock one which I'd like to retain for simplicities sake (eg, when other sysadmins are on the box and don't know that it's actually "firewall" instead of "iptables" when calling service or chkconfig)... And I generally hate reinventing the wheel, especially for something as "small" as this
I use a script to generate the iptables rules (with the variables in it) then use iptables-save > /etc/sysconfig/iptables to save those rules in case of a reboot. Result is I get a readable script (with comments) that I can understand, but I don't have to change any inbuilt functionality.
 
Old 04-09-2010, 03:49 AM   #6
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by bakdong View Post
I use a script to generate the iptables rules (with the variables in it) then use iptables-save > /etc/sysconfig/iptables to save those rules in case of a reboot. Result is I get a readable script (with comments) that I can understand, but I don't have to change any inbuilt functionality.
That's not a half bad idea actually if I can't figure out how to do this.

Have a script generate a save file, then load that using iptables-restore. Has the benefit of being atomic so if there's a syntax error in the rules, it won't bork the current rules
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Second Gateway for Alias ETH0 linchat Linux - Networking 2 01-06-2006 04:10 PM
sendmail sending on alias IP eth0:1 Finlay Linux - Networking 10 11-28-2005 12:27 PM
Eth0 IP Alias Problem assyrian47 Slackware 1 04-20-2005 11:50 AM
Firewall WAN eth0 LAN eth1 self-bridges, eth0 does all routeing. Nichole_knc Linux - Networking 5 07-29-2004 02:33 PM
ifcfg-eth0:X alias problem dgenne Linux - Networking 1 03-17-2002 01:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration