# Add More IPs to NIC



## dixonjp (Apr 23, 2011)

Hey all,

I am wanting to add more than 1 IP to my one NIC. I read the FreeBSD man page here, http://www.freebsddiary.org/ip-address-change.php
and it says to add 
	
	



```
ifconfig rl0 alias 192.168.0.57 netmask 0xffffffff
```
 in /etc/rc.conf. However, say I have 1 ip on the nic, and now I added the above, what would I do for the 3rd IP? instead of 
	
	



```
netmask 0xffffffff
```
 could I use 
	
	



```
255.255.255.1
```
 (the main IP netmask for nic is 255.255.255.0), and then for the 3rd 255.255.255.2?


----------



## mamalos (Apr 23, 2011)

Say you want to have 3 IPs on your NIC: 10.0.0.1/24, 10.1.2.1/24 and 10.1.3.1/24. Your rc.conf should look something like this:


```
ifconfig_re0="inet 10.0.0.1/24"
ifconfig_re0_alias0="inet 10.1.2.1/24"
ifconfig_re0_alias1="inet 10.1.3.1/24"
```

If re0 is your interface's name. The netmask you mention does *not* have anything to do with the number of IPs your interface has. Your netmask is related to your network's setup (it implicitly shows your network's address), and shouldn't be altered unless the your network changes. 

I remember that if I wanted to have two IPs on the same interface that belonged on the same subnet, I used to give a netmask of /32 to the second address and it used to work, but I haven't tried it for a long time.


----------



## dixonjp (Apr 24, 2011)

I thought so... However, I tried this


```
ifconfig_re0="inet 204.00.000.00  netmask 255.255.255.0"
ifconfig_re0_alias0="inet 204.00.000.00  netmask 255.255.255.0"
ifconfig_re0_alias1="inet 204.00.000.00  netmask 255.255.255.0"
```
and it killed the networking.. 

204.00.000.00 is really the ip's..


----------



## wblock@ (Apr 24, 2011)

dixonjp said:
			
		

> I thought so... However, I tried this
> 
> ifconfig_re0="inet 204.00.000.00  netmask 255.255.255.0"
> ifconfig_re0_alias0="inet 204.00.000.00  netmask 255.255.255.0"
> ...



Mysterious, and probably the reason people can't help you.

The web page you pointed to shows a nonfunctional example:


> In this article, I will use 192.168.0.56 as the original IP address and 192.168.0.57 as the new IP address. In reality, the change is from a.b.c.56 to x.y.z.56 (i.e. all but the last octet will change).



Are youe trying to create multiple addresses in the same subnet?  Why?


----------



## mamalos (Apr 24, 2011)

dixonjp said:
			
		

> I thought so... However, I tried this
> 
> ifconfig_re0="inet 204.00.000.00  netmask 255.255.255.0"
> ifconfig_re0_alias0="inet 204.00.000.00  netmask 255.255.255.0"
> ...



I doubt that this settings would play anywhere. First of all the IP you are trying to set is a network address and not a host address. You would probably need something like 204.0.0.*1* netmask 255.255.255.0. Besides that, you have given three times the same IP on the same interface. 

What exactly are you trying to achieve? What is your network like? What are the IPs of the subnets involved?


----------



## vivek (Apr 25, 2011)

I hope you replaced the re0 with your actual interface name. 


```
hostname="sun.nixcraft.in"
# default vsnl router interface
defaultrouter="202.54.1.200"
# Force 10Mbps for both public and private LAN interace
ifconfig_em0="inet 10.20.110.2 netmask 255.255.255.192 media 10baseT/UTP mediaopt full-duplex"
ifconfig_em1="inet 202.52.1.2 netmask 255.255.255.248 media 10baseT/UTP mediaopt full-duplex"
ifconfig_em0_alias0="inet 10.20.1.226 netmask 255.255.255.0"
ifconfig_em0_alias1="inet 10.20.1.227 netmask 255.255.255.0"
ifconfig_em0_alias2="inet 10.20.1.228 netmask 255.255.255.0"
ifconfig_em0_alias3="inet 10.20.1.229 netmask 255.255.255.0"
ifconfig_em0_alias4="inet 10.20.1.230 netmask 255.255.255.0"
# static routing configuration
static_routes="lan0"
route_lan0="-net 10.0.0.0/8 10.20.110.1"
```

See http://www.cyberciti.biz/tips/freebsd-how-to-setup-2-ip-address-on-one-nic.html


----------



## mamalos (Apr 25, 2011)

vivek said:
			
		

> I hope you replaced the re0 with your actual interface name.



...good point there, vivek  .


----------



## SirDice (Apr 25, 2011)

dixonjp said:
			
		

> instead of
> 
> 
> 
> ...


255.255.255.1 is an illegal subnet mask and suggesting it shows that you really need to read up on IP addresses and subnetting.



> ```
> ifconfig_re0="inet 204.00.000.00 netmask 255.255.255.0"
> ```



You are assigning a network address to the interface. It's no small wonder it killed your network.


http://www.tcpipguide.com/free/index.htm


----------



## ecazamir (Apr 28, 2011)

Isn't it easier to use this configuration?

```
ifconfig_re0="up"
ipv4_addrs_re0="10.0.[color="Red"]0.1/24[/color] 10.0.[color="Red"]0.2/32[/color] 10.0.[color="Red"]0.3/32[/color] 10.0.[color="Red"]1.1/24[/color] 10.0.[color="Red"]1.2/32[/color]"
```
Each subnet must have the full subnet netmask listed only for the first ip address in the block, subsequent addresses on the same subnet must have a /32 subnet mask.


----------



## troysunix (Apr 28, 2011)

@ecazamir,

Using 'ipv4_addrs_re0' as you've shown is the suggested means of handling this per rc.conf(5).  The reason is if you skip an alias instance as in the following:

```
ifconfig_em0_alias0="inet 10.20.1.226 netmask 255.255.255.0"
ifconfig_em0_alias1="inet 10.20.1.227 netmask 255.255.255.0"
ifconfig_em0_alias2="inet 10.20.1.228 netmask 255.255.255.0"
ifconfig_em0_alias4="inet 10.20.1.230 netmask 255.255.255.0"
```
any subsequent aliases will not be configured.


----------



## ecazamir (Apr 29, 2011)

@troysunix: Yes, the old style configuration may lead to missing aliases.
BTW, a subnet mask different than /32 can't be set for the 2nd, 3rd... Nth alias in a specific subnet. The kernel will complain that 'the route already exists'. In your example, the first address is 10.20.1.226/24, the subsequent addresses should have 255.255.255.255 if the subnet is the same (10.20.1.x/24).


----------



## troysunix (Apr 29, 2011)

@ecazamir,

Nice catch.  Unfortunately, I let repetition get the better of me on the netmasks.


----------

