Device and network interface - linux

I have wifi and ethernet card in my computer.
Under linux is there a way to know which device is using which network interface?

Generally, you can run command "ip a" and check all the network interfaces connected: from the name of the interface you can see which kind of connection it's related to the interface, i.e.:
eth0
Some kind of cabled connection
wlp1
Some kind of wireless connection
This applies to default names, since you can always change the interface name.

Related

2 wifi adapters connected to 2 separate networks. How to use one of them only?

I have 2 different wireless USB adapters: wlan0 and wlan1.
I have an access to 2 Wifi networks: NETWORK_FOO and NETWORK_BAR.
wlan0 connects to NETWORK_FOO. wlan1 connects to NETWORK_BAR.
I'd like to configure it as follows:
wlan0 automatically makes a connection to NETWORK_FOO and OS always chooses this network for web connection.
wlan1 automatically makes a connection to NETWORK_BAR but OS doesn't use this network.
wlan1 connection to NETWORK_BAR should be available for VM guest running on this machine.
How to do it?
(I know there's a bridge connection option, but don't know how to prevent OS from using NETWORK_BAR connection)
Add the rules in route table. By default windows will connect to internet using network adapter based on routing information. It is automatically generated information. You can change the routing information.

PPPd over SOCAT using INTERFACE option

My objective is to use pppd over socat. I have two Ubuntu boxes with eth0 connected (physically) to each other. I can ping both the IP addresses. I do the below on each Ubuntu box.
Create a pseudo serial device and link it to my network interface "eth0".socat PTY,link=/dev/ttyp10 INTERFACE:eth0
Use pppd on this pseudo serial device.
Device A:
pppd noauth /dev/ttyp10 10.10.10.10:20.20.20.20
Device B:
pppd noauth /dev/ttyp10 20.20.20.20:10.10.10.10
I see that my ppp0 interface gets created for a short time but I cannot ping both the IP addresses (10.10.10.10 or 20.20.20.20). I know my solution is not complete as I need to specify how my pppd packets must be routed from my eth0 interface but not sure how to do it (I used tcpdump on eth0 interface and found some data).
I tried the same experiment by binding socat to a TCP server/client and it worked.
Device A:
1. socat pty,link=/dev/ttyp10,raw,echo=0 TCP4-LISTEN:7001,reuseaddr &
2. pppd noauth /dev/ttyp10 10.10.10.10:20.20.20.20
Device B:
1. socat pty,link=/dev/ttyp10,raw,echo=0,waitslave TCP4:20.1.1.2:7001 &
2. pppd noauth /dev/ttyp10 20.20.20.20:10.10.10.10
Note: 20.1.1.2 is the "eth0" IP address of Device A. With this my ppp0 interface is up and I can ping both IP addresses (10.10.10.10 and 20.20.20.20).
Why I need to use the pseudo serial device when I have a working eth0 interface is a different question and lets not discuss that.
You probably want to adapt this example taken from the socat man page:
socat PTY,link=/var/run/ppp,rawer INTERFACE:hdlc0
circumvents the problem that pppd requires a serial device
and thus might not be able to work on a synchronous line
that is represented by a network device. socat creates a PTY
to make pppd happy, binds to the network interface hdlc0,
and can transfer data between both devices.
Use pppd on device /var/run/ppp then.
In this example, the interface is an synchronous line (seen by the OS as a HDLC interface). pppd uses (by default) a HLDC-like framing so it makes sense to pipe the raw data from pppd to the HDLC device.
In your case, you are using an Ethernet device and this does not make much sense to do the same thing.
In your second example, you managed to transport your PPP session over TCP which is a quite simple and viable option. Another solution in your case would be to use PPPoE which is designed for transporting PPP over Ethernet.

How to switch wifi channel without dropping connection?

We are developing small internet connected device that connects via wifi and does some work. It is controlled via mobile app.
For configuration purposes we use wi-fi module that can work in both STA + AP modes simultaneously via two interfaces wlan0 and wlan1. One of the interfaces works in Master mode. Phone connects to the device via wlan1 and sends command for the device to connect to another network and waits for result. Device in turn connects to another wi-fi network using wlan0 and notifies the phone if connection was successful or not.
But there is one issue. Both interfaces (wlan0 and wlan1) must work on the same channel as we have single hardware module. This causes channel of wlan1 to change in order to match of channel for wlan0.
Here comes the problem. When channel changes phone looses connection with the device. Is there a way to change wi-fi channel but keep connection between the device and mobile phone?
Our wi-fi module is rtl8723bu.
Linux 3.4.103.
Wifi daemons: hostapd v0.8.x_rtw_r7475.20130812_beta, wpa_supplicant v2.3.
UPDATE
Here is more clearly description what is going on on device.
Let's assume that the phone already connected to Device wlan1 interface with essid DeviceAp which is on channel 1. We have a Router with essid RouterAp which is on channel 6. Device interface wlan0 is not configured and not running.
(Step1 on image below).
Then the phone sends a request to the device to connect to RouterAp.
(Step2 on image below).
When wlan0 starts connecting to RouterAp it changes working channel. Because WiFi module can work only on one channel. The channel of wlan1 also changes (maybe in hard way). Therefore Phone lost DeviceAp and starts roaming.
(Step3 on image below).
SO the update question is:
Is there a way to tell the Phone (or other device) about network change? Or perhaps increase the likelihood that the phone is connected back to DeviceAP.
This behavior is very similar to the process of setting up Google Chromecast.
Chromecast also has two wireless interfaces and change the channel, but the Phone does not lose connection with it.
Image:
http://postimg.org/image/soh78vd17/

Is my current approach to force outgoing packets through a bonded interface as the gw device appropriate?

I have two NIC cards with 4 ports each on Redhat 6.1.
When the application comes up, it creates a bonded interface with one port from each NIC (example: eth1 and eth4), and assigns a virtual IP to that interface. Once this interface is up, all the packets from this machine should go through the bonded interface.
To achieve this currently, I'm changing the default gw device name to the bonded interface using the ip route command: ip route replace default via 10.3.2.1 dev INT-BOND.
When stopping the application, we bring down the bonded interface and change the default gw device name back to eth0.
The problem with my approach is if someone brings down the bonded interface (ifdown), then it removes the default gw.
I need confirmation that my currently working approach is fine to proceed with going forward; otherwise, should I go with modifications to the iptables/ip rules, or are there any better suggestions?

Selecting an Interface when Multicasting on Linux

I'm working with a cluster of about 40 nodes running Debian 4. Each node runs a daemon which sits and listens on a multicast IP.
I wrote some client software to send out a multicast over the LAN with a client computer on the same switch as the cluster, so that each node in the cluster would receive the packet and respond.
It works great, except when I run the client software on a computer that has both LAN and WAN interfaces. If there is a WAN interface, the multicast doesn't work. So obviously, I figure the multicast is incorrectly going over the WAN interface (eth0), rather than the LAN (eth1.) So, I use the SO_BINDTODEVICE socket option to force the multicast socket to use eth1, and all is well.
But I thought that the kernel's routing table should determine that the LAN (eth1) is obviously a lower cost destination for the multicast. Is there some reason I have to explicitly force the socket to use eth1? And, is there some way (perhaps an ioctl call) that I can have the application automatically determine if a particular interface is a LAN or WAN?
If you don't explicitly bind to an
interface, I believe Linux uses the
interface for the default unicast
route for multicast sending.
Linux needs a multicast route, if none exists you will get a EHOSTUNREACH or ENETUNREACH error. The LCM project documents this possible problem. The routing will be overridden if you use the socket option IP_MULTICAST_IF or IPV6_MULTICAST_IF. You are supposed be able to specify the interface via scope-id field in IPv6 addresses but not all platforms properly support it. As dameiss points out, Stevens' Unix Network Programming book covers these details, you can browse most of the chapter on multicast via Google Books for free.
If you don't explicitly bind to an interface, I believe Linux uses the interface for the default unicast route for multicast sending. So my guess is that your default route is via the WAN interface.
Richard Stevens' "Unix Network Programming, Vol. 1", chapter 17 (at least in the 3rd edition), has some good information and examples of how to enumerate the network interfaces.

Resources