Setting Two IPs on one NIC

I have a single NIC (eth0) and it has a single, static public address assigned to it. I would like to assign an additional private address (192.168.1.68) to the NIC to make accessing my router more convenient, but I’m having a little trouble.

I’m not using the Network Settings module in YaST because whenever I’ve tried before it has usually resulted in my internet connection failing and being unable to remove the alias info I tried setting in YaST. So, instead, I’m just trying to do it by editing the configuration directly. I’m also using it as an opportunity to learn a little bit more about Linux. :smiley:

So far, all I’ve done is add an extra line to my /etc/sysconfig/network/ifcfg-eth0 file. Originally the contents of the file were as follows.

BOOTPROTO='static'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR='XXX.XXX.XXX.XXX/21'
MTU=''
NAME='SiS900 PCI Fast Ethernet'
NETWORK=''
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'

So I added a line to include the local address 192.168.1.68/24 so that I could access my router at 192.168.1.254. The file then looked like the following.

BOOTPROTO='static'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR='XXX.XXX.XXX.XXX/21'
IPADDR_LOC='192.168.1.68/24'
MTU=''
NAME='SiS900 PCI Fast Ethernet'
NETWORK=''
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'

So I saved the changes, restarted the eth0 interface and then tried to connect to my router. Naturally, it failed and I realized that I hadn’t set the default gateway for the local address (which needs to be the address of the router: 192.168.1.254).

I remembered that when I looked in man ifcfg and /etc/sysconfig/network/ifcfg.template that it said you could set options that are normally global in their scope to specific additional addresses that you have set. So I had another look in man ifcfg and saw the IP_OPTIONS[suffix] command. There wasn’t very much information about it, though, so I just took a guess and tried IP_OPTIONS_LOC=‘GATEWAY=192.168.1.254’. The config file then looked like this.

BOOTPROTO='static'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR='XXX.XXX.XXX.XXX/21'
IPADDR_LOC='192.168.1.68/24'
IP_OPTIONS_LOC='GATEWAY=192.168.1.254'
MTU=''
NAME='SiS900 PCI Fast Ethernet'
NETWORK=''
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'

Naturally, this didn’t work either. Can anyone tell me how to specify the gateway for the additional local address?

I would try to set this extra route via YaST, too (tab “Routing” in network configuration).

P.S.

If you only want to access your LAN (192.168.1.0/24), then you normally don’t need an extra route.

What Akoellh suggested is the best option instead of directly manipulating those configuration files.

Also, if you are curious, you can very well have a look at what Yast has done to those configuration files.

Well YaST was my first instinct, but whenever I tried to do this with YaST it just wouldn’t work and it wouldn’t undo additions to the config. If I tried to delete something from the config it would show as being removed, but the next time I’d go into the network config module of YaST, the unwanted changes would be back again.

I know that I wouldn’t normally need to make any changes to my setup to access my LAN if I was on a single IP address with my router performing NAT (as is the case for most domestic users), but my case is slightly different. I have 4 static, public IP addresses. One of these addresses is assigned to my PC and my router is in bridge mode. So my default gateway is not the router in my home like it is for most people. Instead, my default gateway is a device in my local telephone exchange centre. So a request for 192.168.1.254 passes straight through my router at home and then just gets dropped by my gateway at the exchange because it’s in the class C local/private IP range.

At the moment, if I want to connect to my router I have to go in to the network settings module of YaST and change my IP address from my public class A address (with a netmask prefix of 21) to the private class C address 192.168.1.68/24 and change the address of my default gateway (again from a public class A address to the private class C address of 192.168.1.254).

I’d like to be able to access the internet and my router without having to keep changing the settings back and forth. So basically, I want to be able to configure my settings so that my normal settings are used by default, but when I’m accessing the 192.168.1.0/24 network I want to use a host IP address of 192.168.1.68/24 with a default gateway address of 192.168.1.254.

How should I be trying to do this in YaST? I get the distinct impression that my network settings configuration module in YaST doesn’t work properly.