What does this ip linux command mean? - linux

ip link add link eth2 dev col0000000000a7 type macvlan mode bridge
I can't find this usage in the manual.
Is it a combination of two commands?

See this link for details
The ip command is used to assign an address to a network interface and/or configure network interface parameters on Linux operating systems. This command replaces old good and now deprecated ifconfig command on modern Linux distributions.
Looks like it is adding a bridging device to interface eth2.
Run $ ip a show eth2 would give you more info on that particular interface.

Related

OPNSense in a Proxmox VM, nested in Azure VM, trying to spoof VM NIC to transparently relay to host NIC

I am trying to set up OPNSense VM inside a Proxmox, which is running in a Azure VM with nesting enabled. I have my reasons to do it, so please spare me the "why not go native" questions.
Since azure VMs don't support vIOMMU (note the "v" in vIOMMU stands for virtualized IOMMU, for L2 instances), I cannot pass the interface further from Proxmox to OPNSense, so I need to get by using bridges.
The host setup is:
WAN over eth0
vmbr0 with eth0 assigned to it
The bridged interfaces are in promiscuous mode.
The actual configuration is:
iface eth0 inet manual
auto vmbr0
iface vmbr0 inet manual
bridge-ports eth0
bridge-stp off
bridge-fd 0
The guest configuration is:
VirtIO NIC attached to vmbr0, with MAC overridden using same
address as the eth0
Firewall: NO
MAC Filter: NO
Running dhclient on eth0 or vmbr0 correctly discovers and assigns an IP address.
Now, I am trying to get the OPNSense in a VM to get that IP address instead and to relay its traffic via the vmbr0 transparently outside of the host. I have done something very similar previously between OpenWRT running in a VM and another VM, using OpenWRT's "trivial relay" (kmod-trelay, see https://forum.openwrt.org/t/howto-kmod-trelay/49610/2, also https://github.com/openwrt/openwrt/commit/c3bba7f8c61ee98265bcffef8ee86e22aa89bbe9), and despite that this particular case is much simpler, I can't get the VM to communicate with the ISP properly. I tried simply by spoofing the eth0's MAC address by setting the OPNSense VM's interface to it, but that's not enough.
I also checked the traffic on both ends using tcpdump, and, interestingly, vmbr0 does see the DHCP requests coming from the VM, and the ISP does respond, but that response never reaches the VM, nor the tap interface corresponding to the VM that Proxmox assigned to the bridge.
What am I missing here?
FYI, the solution was to use macvtap in passthru mode. Alternative would be to use ipvtap if I needed more VMs to share the same MAC address.

Means to get IP and MAC information from a list of known Hostnames

I have a list of hostnames for mixed Linux distros (some Solaris, some RedHat, some Ubuntu), I need to get the IP and MAC for any Ethernet devices on each distro.
I don't have root access to any of these servers, so I wrote a bash script on one that remotely runs on the others and returns IP and MAC parsed from output of ifconfig. Because this script uses an expect file to pass in my password, it takes a long time to execute and is not very elegant.
There has to be a better way to do this. I know of a few tools that can do it for me but unfortunately I can't install any additional packages as I don't have permissions to do so.
The output of arp -a gives exactly what I want, but the problem with this is some of these entries seem to have multiple IPs and hostnames binded to the same MAC address. So I get entries like:
HOSTNAME-1 (IP-1) at SAME_MAC_ADDR [ether] on eth0
HOSTNAME-2 (IP-2) at SAME_MAC_ADDR [ether] on eth0
? (IP-2) at SAME_MAC_ADDR [ether] on eth0
Is there a way to firstly get all IPs and MAC addresses from the list of hostnames I have? I'm guessing arp is what I need here?
Secondly, is there a means to get all additional hostnames or IPs associated with each MAC address if there are duplicates?
The arp command will show the list of MAC address and associated IP addresses of hosts known to the one you are connecting to.
ifconfig is the right tool to use (or "ip a" in some distros). Why don't you try to put a cron job in every machine to store the result of "ip a" or "ifconfig" into a tempfile and instead or executing the command in every remote host, you just donwload this file and parse in your local server?
If not, they only way to get accurate information of network adapters in a *IX box is to get into the host and ask for this info.

Configuration of a NIC from a Linux Bash Shell

I have a Dell laptop running the following version of RedHat Linux:
2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:02 EDT 2007 i686 i686 i386 GNU/Linux
It has an Ethernet-over-USB connection to a device under test (DUT). This interface to the DUT is usually configured as follows:
IP address: 104.4.40.2
Netmask: 255.255.255.0
Default gateway: 104.4.40.1
The default gateway points to the DUT.
Occasionally, I need to change the IP address / default gateway to 104.4.20.2 and 104.4.20.1, respectively. (The netmask remains 255.255.255.0).
I need to make this change when I load a new configuration onto the DUT that changes its IP address. (This configuration loading is done over a second interface that is unrelated to the interface I'm discussing here.)
When I make the corresponding change to the Linux box's network configuration using the GUI, everything works fine. But I often work remotely by shelling in via ssh. So, all I have available in that case is a Bash shell.
I've used command "ifconfig" (to set the IP address and netmask) and command "route" (to install the default gateway forwarding entry) to reconfigure the interface, and I then used "iconfig" to bring the interface down and back up to try to get the changes to "take".
When I check the interface settings with "ifconfig", they looks right. When I check the forwarding table with "route", everything looks good (including the default gateway). Yet, when I try to ping the DUT, I get no reponse. If I configure the interface yet again using the GUI, I can then ping the DUT.
I am clearly doing something wrong. Could someone please kindly show me the Bash shell command line commands I need to issue to change the IP address and default gateway of interface "eth1"?
Thank you in advance!
If I've got you right, you need these two simple commands:
vim /etc/sysconfig/network-scripts/ifcfg-eth1 //modify the configuration
service network restart
Also you can write a primitive bash/perl/python wrapper for your routines...
This answer may be useful for you too.

Tap interfaces and /dev/net/tun device, using ip tuntap command

I'm using ip tuntap to create a tap interface, like this:
$ sudo ip tuntap add mode tap tap0
Afterwards, I set the interface up and address it with the common IP commands. I can see then my interface up and addressed with a simple ifconfig.
Now, I was told by a teacher that by creating a tap interface (named tap0 in that case), I would find a /dev/net/tap0 node, and that I would be able to write in it or to read it. However, I can't find it. I "just" have a /dev/net/tun.
Do I have to deal with this tun node, or am I supposed to really have a tap0 node?
It's been a long time since the question was asked, but I thought it would be a good idea to post an actual answer for future reference.
Tap interfaces, as well as tun interfaces, are virtual interfaces provided by the in-kernel TUN/TAP device driver. The only interface this driver provides initially is the character device /dev/net/tun mentioned in the question.
By issuing:
$ sudo ip tuntap add mode tap tap0
we instruct ip tuntap to create a network interface named tap0, which is accomplished using the proper ioctl(2) calls on the aforementioned device file /dev/net/tun, to communicate with the underlying TUN/TAP device driver, as we can observe in ip tuntap's source code.
One of these ioctl(2) calls (the one with TUNSETIFF option, which is called first) returns a file descriptor associated with the new virtual interface that was created and can be used by processes.
Summing it up:
Do I have to deal with this tun node, or am I supposed to really have a tap0 node?
The /dev/net/tun device file is only used as a starting point to create both tap and tun interfaces, by userspace utilities like iproute2. In the context of this question, there's no need to deal with it as ip tuntap does this job for us.
Any extra /dev/net/tap0 device files are not needed or expected to be created for the processes to use the tap interfaces.
you need to activate that link with command
ip link set dev tap0 up
after that you can use it.
Commented out all the items in /lib/systemd/network/99-default.link & rebooted.
All mac addresses (excepted phys adapter) are randomized again.

How does linux pull my mac address to send over the link?

I want to build a MAC address spoofer that spits out a randomize mac address everytime my computer boots up. My question is how and from where do all my computer programs in linux pull up my MAC address. I know that my wi-fi network driver is responsible for telling my network card what to send, but from where does that driver get my MAC address? I also know that a MAC address is called a hardware address, however since it is possible to spoof MAC addresses, then it must only mean that the MAC address on my network card doesn't have to be used when sending information. I would like to know how this can be done as well.
Also when randomizing my MAC address this ought to work with all other programs such as my web-browser and whatever else that I use, which shouldn't be a problem since thats really an application layer ... not link layer
Thanks
The MAC address is usually stored in some kind of EEPROM on the network card. This address is read during initialization by the network adapter driver and used by the MAC layer when assembling/sending netowrk packets.
The MAC address used can be changed on the command line using "ifconfig" via the "hw" option:
hw class address
Set the hardware address of this interface, if the device driver
supports this operation. The keyword must be followed by the
name of the hardware class and the printable ASCII equivalent of
the hardware address. Hardware classes currently supported
include ether (Ethernet), ax25 (AMPR AX.25), ARCnet and netrom
(AMPR NET/ROM).
ifconfig essentially uses the SIOCSIFHWADDR ioctl (see http://linux.die.net/man/7/netdevice) to set the MAC address.
In some cases it might even be possible to change the MAC address stored on the network adapter itself, see http://linux.die.net/man/8/ethtool - but I wouldn't recommend doing that.
The only thing that cares about your MAC address is the NIC itself. There should be no programs that use the MAC address (including browsers). Since MAC addresses are used on the physical layer -- that's the only thing that will read your MAC (such as routers, switches, etc).
To set the MAC address of your NIC you can use the ifconfig command: ifconfig eth0 hw ether ##:##:##:##:##:## (you might have to take your network down first, set it, and then bring it up. IE: ifconfig eth0 down; ifconfig eth0 hw ether ##:##:##:##:##:#; ifconfig eth0 up)

Resources