LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2023, 05:24 AM   #1
Jason.nix
Member
 
Registered: Feb 2023
Posts: 568

Rep: Reputation: 10
Post A question about virtual interface


Hello,
I created a virtual interface like the below:
Code:
# touch /etc/network/interfaces.d/ifcfg-enp0s3:0
# nano /etc/network/interfaces.d/ifcfg-enp0s3:0

auto enp0s3:0
iface enp0s3:0 inet static
address 10.0.5.20
netmask 255.255.255.0
Then:
Code:
# systemctl restart networking
#
# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:feed:b47c  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:ed:b4:7c  txqueuelen 1000  (Ethernet)
        RX packets 7624  bytes 2522366 (2.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5147  bytes 869088 (848.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s3:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.5.20  netmask 255.255.255.0  broadcast 10.0.5.255
        ether 08:00:27:ed:b4:7c  txqueuelen 1000  (Ethernet)
...
But, why I can't use it for some common network tasks:
Code:
# ping -I enp0s3 google.com
PING google.com (216.239.38.120) from 10.0.2.15 enp0s3: 56(84) bytes of data.
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=1 ttl=63 time=35.3 ms
64 bytes from any-in-2678.1e100.net (216.239.38.120): icmp_seq=2 ttl=63 time=71.7 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 2 received, 33.3333% packet loss, time 2100ms
rtt min/avg/max/mdev = 35.292/53.511/71.730/18.219 ms
#
# ping -I enp0s3:0 google.com
ping: invalid source address: enp0s3:0

Thank you.
 
Old 07-26-2023, 08:24 AM   #2
Jason.nix
Member
 
Registered: Feb 2023
Posts: 568

Original Poster
Rep: Reputation: 10
Hello,
Any idea?
Suppose you have a NIC on a server and you want to set five public IP addresses on it, then you should be able to communicate with these other IP addresses and use them.
 
Old 07-26-2023, 01:36 PM   #3
yvesjv
Member
 
Registered: Sep 2015
Location: Australia
Distribution: Slackware, Devuan, Freebsd
Posts: 581

Rep: Reputation: Disabled
Did you create vlans for your sub-interfaces?
 
Old 07-26-2023, 01:57 PM   #4
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
try ping -I enp0s3:0 google.com
 
Old 07-26-2023, 03:17 PM   #5
Jason.nix
Member
 
Registered: Feb 2023
Posts: 568

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by yvesjv View Post
Did you create vlans for your sub-interfaces?
Hello,
Thanks.
Not really. Why a VLAN?
 
Old 07-26-2023, 03:19 PM   #6
Jason.nix
Member
 
Registered: Feb 2023
Posts: 568

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by elgrandeperro View Post
try ping -I enp0s3:0 google.com
Hello,
Thank you.
I will test it. What does this command do?
 
Old 07-26-2023, 11:10 PM   #7
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
When you don't specify a source binding, then the system is going to use the default route interface. I believe if you use -S IP to be the source of your ping OR -I interface, then it will use the alternate interface. So ping -s 10.0.5.20 google.com will use the alternate ip as well -I interface.
 
Old 07-27-2023, 06:20 AM   #8
Jason.nix
Member
 
Registered: Feb 2023
Posts: 568

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by elgrandeperro View Post
When you don't specify a source binding, then the system is going to use the default route interface. I believe if you use -S IP to be the source of your ping OR -I interface, then it will use the alternate interface. So ping -s 10.0.5.20 google.com will use the alternate ip as well -I interface.
Hello,
Thank you so much for your reply.
I have done this before and I created this thread because of it:
Code:
# ping -I enp0s3:0 google.com
ping: invalid source address: enp0s3:0

Last edited by Jason.nix; 07-27-2023 at 06:22 AM.
 
Old 07-27-2023, 08:45 AM   #9
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
Yeah, so you just use the -I or -S with your source ip address. When people test (and have multiple ips) they often forget to set the source and it gives them the wrong results. This is often when pinging from a router where there might be lots of paths out or routing instances.

Most tools where the source makes a difference have a way to bind the source.
 
Old 07-27-2023, 03:53 PM   #10
yvesjv
Member
 
Registered: Sep 2015
Location: Australia
Distribution: Slackware, Devuan, Freebsd
Posts: 581

Rep: Reputation: Disabled
Cool

Quote:
Originally Posted by Jason.nix View Post
Hello,
Thanks.
Not really. Why a VLAN?
Vlans are used to transport different networks across a single ethernet cable.
Linux support it: https://www.baeldung.com/linux/vlans-create

The switch/router the ethernet cable will connect to from your server must also support it plus creating Switch Virtual Interfaces (SVI) to route the different subnets.
 
Old 07-27-2023, 04:23 PM   #11
Jason.nix
Member
 
Registered: Feb 2023
Posts: 568

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by elgrandeperro View Post
Yeah, so you just use the -I or -S with your source ip address. When people test (and have multiple ips) they often forget to set the source and it gives them the wrong results. This is often when pinging from a router where there might be lots of paths out or routing instances.

Most tools where the source makes a difference have a way to bind the source.
Hello,
Thank you for your reply.
You mean multipath routing?
 
Old 07-27-2023, 09:23 PM   #12
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
That would be one case, you have if you 2 paths out, you need to bind to the appropriate source to route to the right interface. In your case (simple added ip) I would not consider that to be multipath because your are using the same interface for both paths, hardly redundant. Multi Path refers to connecting to 2 separate networks and interfaces to provide redundancy.
 
Old 07-28-2023, 08:30 AM   #13
KatrinAlec
Member
 
Registered: Feb 2012
Posts: 116

Rep: Reputation: 13
Have you tried instead of -I enpx -I 10.0.5.20?

You can also use SNAT to change the source address.
 
Old 07-28-2023, 01:48 PM   #14
Jason.nix
Member
 
Registered: Feb 2023
Posts: 568

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by elgrandeperro View Post
That would be one case, you have if you 2 paths out, you need to bind to the appropriate source to route to the right interface. In your case (simple added ip) I would not consider that to be multipath because your are using the same interface for both paths, hardly redundant. Multi Path refers to connecting to 2 separate networks and interfaces to provide redundancy.
Hello,
Thanks again.
You said:
Quote:
In your case (simple added ip)...
What do you mean?
Same interface? Can you tell me more?
 
Old 07-28-2023, 01:51 PM   #15
Jason.nix
Member
 
Registered: Feb 2023
Posts: 568

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by KatrinAlec View Post
Have you tried instead of -I enpx -I 10.0.5.20?

You can also use SNAT to change the source address.
Hello,
Thank you for your reply.
Is you mean:
Code:
# ping -I 10.0.5.20 google.com
SNAT? How?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to create a virtual/clone interface to map to another existing interface ? Mac83 Linux - Networking 17 07-22-2019 03:14 PM
[CLOSE, DUPLICATE] Is it possible to create a virtual/clone interface to map to another existing interface ? Mac83 Linux - Networking 3 06-19-2019 12:26 AM
Outgoing local trafic over virtual interface has not virtual ip address :-( tkmbe Linux - Networking 3 08-25-2009 08:03 PM
Adding virtual interface for IP based virtual host pridefc Linux - General 6 03-16-2008 03:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration