LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to assign two IPs on same NIC (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-assign-two-ips-on-same-nic-611662/)

arvind_77_99 01-07-2008 01:38 AM

how to assign two IPs on same NIC
 
I am using Fedora Core7. Can Anybody help me to assign two IP addresses on same NIC.

Arvind

Uncle_Theodore 01-07-2008 01:44 AM

Behold the power of GOOGLE! :D
http://technodigits.wordpress.com/20...card-in-linux/

uffe2 01-07-2008 02:56 AM

With static IP-addresses is just to define them.
With DHCP it's not possible

mrrangerman 01-07-2008 06:08 AM

Quote:

uffe2
With static IP-addresses is just to define them.
With DHCP it's not possible
Um that's not true, if he wants he could have both DHCP. Or he could have his first interface DHCP and the sub-interface static. I think it would be better to have static, as DHCP can change, but as a rule once an IP address has been issued DHCP will issue that same address the next time to the same interface/sub-interface.


Quote:

arvind_77_99

I am using Fedora Core7. Can Anybody help me to assign two IP addresses on same NIC.
Edit the file that Fedora places the interface info in, in Debian it's located in /etc/networking/interfaces.

Code:

auto eth0
iface eth0 inet static
    address 192.168.1.20
    netmask 255.255.255.0
    broadcast 192.168.1.255
    network 192.168.1.0
    gateway 192.168.1.1

## Sub-netinterface added

auto eth0:0
iface eth0:0 inet static

    address 192.168.1.21  <--- can not be the same as any other IP
    netmask 255.255.255.0
    broadcast 192.168.1.255
    network 192.168.1.0
    gateway 192.168.1.1

EDIT: uffe2
Well I had some time when I got home from work to check out if you could have DHCP on both for sure, it seems we were both half right. I couldn't get DHCP to work on both the primary and sub-interface at the same time, but I had no problem having DHCP on the primary interface and static on the sub-interface.
I was going by some linux lessons I have, and the instructor said it could be done. If it can, I wasn't able to get it to work.

LlNUX 01-08-2008 04:48 AM

http://blog.linuxconfig.org/configur...sses-on-linux/

uffe2 01-09-2008 08:14 AM

Subnet interface ? What's that ?
Is each "subnet interface" defined with there own unique MAC address ?
If "YES" then: How do you configure the MAC address for the second MAC address for subnet interface 2 ?

If "NOT", the DHCP server can't delivery more than one IP-address to each MAC-address (on the DHCP client discovery request from the host) ?
If each subnet interface has one unique MAC address, the DHCP server see each MAC address as different host's !



Quote:

Originally Posted by mrrangerman (Post 3014215)
Um that's not true, if he wants he could have both DHCP. Or he could have his first interface DHCP and the sub-interface static. I think it would be better to have static, as DHCP can change, but as a rule once an IP address has been issued DHCP will issue that same address the next time to the same interface/sub-interface.



Edit the file that Fedora places the interface info in, in Debian it's located in /etc/networking/interfaces.

Code:

auto eth0
iface eth0 inet static
    address 192.168.1.20
    netmask 255.255.255.0
    broadcast 192.168.1.255
    network 192.168.1.0
    gateway 192.168.1.1

## Sub-netinterface added

auto eth0:0
iface eth0:0 inet static

    address 192.168.1.21  <--- can not be the same as any other IP
    netmask 255.255.255.0
    broadcast 192.168.1.255
    network 192.168.1.0
    gateway 192.168.1.1

EDIT: uffe2
Well I had some time when I got home from work to check out if you could have DHCP on both for sure, it seems we were both half right. I couldn't get DHCP to work on both the primary and sub-interface at the same time, but I had no problem having DHCP on the primary interface and static on the sub-interface.
I was going by some linux lessons I have, and the instructor said it could be done. If it can, I wasn't able to get it to work.


uffe2 01-09-2008 08:19 AM

"Virtual IP-address" ?! ...there is a lot of strange definitions....

It's only to define more than one IP-addresses per physical interface.
But, still all IP-addresses are using the same MAC address
on one physical Ethernet interface.



Quote:

Originally Posted by LlNUX (Post 3015337)


uffe2 01-09-2008 08:26 AM

I belive "Virtual IP-address" and subnet interface is the same !
Then each physical Ethernet interface has only one MAC address, then it's possible to only use one ( and only one) IP-address with DHCP per phsical Ethernet interface.

But, maybe someone could write a new NIC-driver and emulate several virtual NIC cards by using serveral MAC addresses per physical Ethernet interface.
If the operating system detect several NIC card, it also support one IP-address per virtual interface used with DHCP.

osor 01-09-2008 02:20 PM

Perhaps I can clear some things up. The process described in the two articles above (which one article calls “Virtual IP-addresses”) is more correctly known as ip aliasing. Using this method, you may add multiple aliases to a network device. All alias devices (whose names consist of the base device, followed by a colon and the alias number) share the same MAC as the base device and all such interfaces will come down (and be deleted) when the base device is brought down.

If you want to have one physical network device with multiple MAC addresses (each of which in turn may have its own IP address and zero or more aliases), you may use something called VLAN Tagging (described in the IEEE802.1Q standards document). To do this on linux, you’ll need the 8021q module loaded (unless it’s compiled into the kernel). Once you create a VLAN tag (with the userspace utility vconfig), you can change its link address the same way you change the link address of a normal interface. In fact, you can even bring the interfaces up and down independently of each other. You should be careful that the new MAC does not conflict with any other MAC addresses in your network.

Here is an example of using 802.1Q tagging to get multiple MAC addresses (as well as IP addresses) on a single device.

Once you have separate MAC addresses, you should be able to use DHCP to configure both each tag separately.

Emerson 01-09-2008 02:28 PM

Code:

mate ~ # ifconfig eth0:0 hw ether 00:00:00:00:00:01
mate ~ # ifconfig eth0:0
eth0:0    Link encap:Ethernet  HWaddr 00:00:00:00:00:01 
          inet addr:192.168.2.56  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


osor 01-09-2008 05:25 PM

Quote:

Originally Posted by Emerson (Post 3017007)
Code:

mate ~ # ifconfig eth0:0 hw ether 00:00:00:00:00:01
mate ~ # ifconfig eth0:0
eth0:0    Link encap:Ethernet  HWaddr 00:00:00:00:00:01 
          inet addr:192.168.2.56  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


Yes, this works fine except that the base device has had its HWaddr altered as well. I believe the point was to alter the alias but leave the base device alone. AFAIK, this is not possible with aliases. It is possible with VLAN tags, which is what I talked about in my previous post (I even provided a hyperlink to a post detailing just that).

For example (using ifconfig):
Code:

# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:01 
          inet addr:192.168.2.55  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
# vconfig add eth0 1
# ifconfig eth0.1 192.168.2.56
# ifconfig eth0.1 hw ether 00:00:00:00:00:02
# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:01 
          inet addr:192.168.2.55  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
eth0.1    Link encap:Ethernet  HWaddr 00:00:00:00:00:02 
          inet addr:192.168.2.56  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

Note that it is always imperative to change the IP address prior to changing the MAC address (unless the VLAN tagged device is brought down). Otherwise, you have a race condition with two differing MAC devices sharing an IP (which should never be allowed to happen).


All times are GMT -5. The time now is 02:55 AM.