[CentOS] How to do virtual IP on NetworkManager

Mon Jan 18 18:03:09 UTC 2021
Stephen John Smoogen <smooge at gmail.com>

On Mon, 18 Jan 2021 at 12:51, Simon Matter <simon.matter at invoca.ch> wrote:

> > On Mon, Jan 18, 2021 at 2:56 PM Jerry Geis <jerry.geis at gmail.com> wrote:
> >
> >> Hi All,
> >>
> >> I use virtual IP from time to time on CentOS 7. just take something like
> >> eth0 and make eth0:1 put in there the IP and subnet and bring up the new
> >> IP
> >> and it works.
> >>
> >> How do I do that with NetworkManager on the command line (assuming all
> >> static IP information)
> >> I do something like this from nmcli to set the static address:
> >> nmcli connection modify eth0 ipv4.method manual ipv6.method ignore
> >> autoconnect yes ipv4.addr 192.168.1.8/24 gw4 192.168.1.1 ipv4.dns
> >> 8.8.8.8
> >>
> >> How then do I add a virtual IP?
> >>
> >> Thanks
> >>
> >> Jerry
> >
> >
> > With nmcli you should use:
> > nmcli con mod eth0 +ipv4.addresses 192.168.1.X/24
> >
> > This would modify your existing ifcfg-eth0 adding the lines:
> >
> > IPADDR1=192.168.1.X
> > PREFIX1=24
> >
> > To have the new setting applied and your new ip alias up and running you
> > can then use
> >
> > nmcli dev reapply eth0
> > (supposing the device name bound to the connection is eth0)
> >
> > You can also manually modify the file adding the two lines above and then
> > run:
> > nmcli con reload
> > nmcli dev reapply eth0
> >
> > I think you should not lose your connection, but always test on a non
> > production machine with the same os version... just for safety
> > HIH,
> > Gianluca
>
> Hi Gianluca,
>
> Am I right that what you describe doesn't add an alias device like eth0:1
> but adds the additional IP address to the eth0 device?
>
> Apart from that, when running with NetworkManager, can one still add a
> temporary eth0:1 alias (with ifconfig/ip), use it and remove it again, or
> does NM somehow prevent this?
>
>
There are several issues which get in the way, but the major one is with
the iproute command replacing net-tools (versus NetworkManager)

https://unix.stackexchange.com/questions/192908/how-do-you-create-an-ip-alias-using-iproute-utils
https://unix.stackexchange.com/questions/87829/difference-between-virtual-interfaces-with-ifconfig-and-iproute2

[The major issues I run into is that ethX is considered a kernel only
interface and may not always point to the same interface depending on the
day of the week.. that gets added onto how iproute wants to do 'aliases'
versus proper port configs and then NetworkManager sits on top and get the
blame :)]



> Regards,
> Simon
>
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> https://lists.centos.org/mailman/listinfo/centos
>


-- 
Stephen J Smoogen.