How to Create an IP Alias in Mac OS X using ifconfig

Aug 5, 2009 - 8 Comments

Terminal in macOS

In some trickier network situations, your computer may be assigned an IP but need an entirely different IP address to access certain network resources. You might be wondering, how on earth do you have two IP addresses at once on the same Mac? The answer; Create an IP Alias!

Using an IP alias allows your Mac to have more than one IP address at the same time, this can allow you to have multiple IP addresses that reference the same machine.

While this is fairly advanced topic, you will find that creating an IP alias is easy to do with the powerful Mac OS X command line utility ifconfig.


To get started, open the command line via Terminal app or your terminal of choice.

How to Create an IP Alias on the Mac via Command Line

Type the following at the command line prompt, this will alias the new IP of 192.168.0.101 to your existing subnet mask, on the en0 network interface:

sudo ifconfig en0 alias 192.168.0.101 255.255.255.0

The syntax therefore for creating an IP alias is as follows:

sudo ifconfig INTERFACE alias new.ip.address subnet.mask.address

You will need to use sudo which requires the root/admin password.

How to Remove the IP Alias

If you want to get rid of the alias, just type:

sudo ifconfig en0 -alias 192.168.0.101

This removes the specified alias at the specified network interface.

There are many uses for this great trick, give it a try yourself if you need multiple LAN IP references to the same machine.

.

Related articles:

Posted by: William Pearson in Command Line, How to, Mac OS, Tips & Tricks

8 Comments

» Comments RSS Feed

  1. Sean Wong says:

    Please note, this is a one time shot, not persistent. Should the server reboot/lose power you’ll have to do this again.

    The recommended way is to modify /etc/IPAliases.conf

    for any clarification, please man IPAliases.conf

    • Will says:

      That would be ideal, but as far as I can tell IPAliases.conf is only in Snow Leopard Server by default. I’m sure you could manually create the appropriate file and enable ipaliases in /etc/hostsconfig though I haven’t tested this.

      – Will

  2. […] How to create an IP Alias in Mac OS X using ifconfig – create an IP Alias to make your LAN administration and general networking life easier […]

  3. Fox Mulder says:

    @Terrence Brown

    IP aliasing is the ability to add more than one IP address to a network interface or resource allowing a node on a network to have multiple connections to a network. For example, if a client or network resource uses DHCP and therefore has a dynamic (changing) IP address, another machine can connect to that client consistently by using an IP alias that will act as a static IP. This makes it so you adjust settings to connect to something like 10.0.0.10 reliably, rather than manually reentering the newly assigned and randomized dynamic address (10.0.0.7 etc). To an average computer user, you could call that a ‘trickier network situation,’ as you say.

    There’s nothing to pay for with IP Aliasing, it’s a free technology that’s been around in the networking and UNIX world for decades. It’s also widely used by Systems Administrators and IT professionals, which is why Apple has included it in their operating system.

  4. Terrence Brown says:

    What do “trickier network situation” and “certain network resources” mean? Do they mean, “trickier network situation where you should be denied access but that won’t stop us from helping you access certain network resources normally forbidden to you because you either haven’t paid or haven’t the clearance?”

  5. […] This post was Twitted by berneau25 […]

  6. This is so cool. Thanks for the tip.

  7. CrackTheMac says:

    Great tip especially with my screwy LAN but this is what worked for me:

    sudo ifconfig en0 alias 192.168.1.101 netmask 255.255.255.255

    might be a version thing so if the above doesn’t work try that (depending on your IP and netmask)

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site