How to check that IP addess is attched to which eth in Linux Machine? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Well I use SUSE11 Linux machine, Is there is a single cmd which gives the eth number to which my IP is attched to ?
Ex:
<1035 sne-70 [u2see] :/home/u2see/nginrun/log>**ifconfig -a | grep addr**
eth0 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:39
inet6 addr: fe80::225:9eff:fed4:7d39/64 Scope:Link
eth2 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:3A
inet addr:192.168.100.70 Bcast:192.168.100.255 Mask:255.255.255.0
inet6 addr: fe80::225:9eff:fed4:7d3a/64 Scope:Link
eth3 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:3B
inet6 addr: fe80::225:9eff:fed4:7d3b/64 Scope:Link
eth4 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:3C
inet addr:**10.19.120.24** Bcast:10.19.120.255 Mask:255.255.255.0
inet6 addr: 2607:f0d0:1002:11::6/64 Scope:Global
inet6 addr: fe80::225:9eff:fed4:7d3c/64 Scope:Link
My IP is "10.19.120.24" And i need to get the output as eth4 by using single cmd..
What cmd i can use ?

You can use GNU awk:
ifconfig -a |awk -v RS="\n\n" '/inet addr:10.19.120.24 /{print $1}'

Related

How do I restart wlan0 with the static ip instead of a dynamic ip? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I have a Raspberry Pi running Raspbian Wheezy. The /etc/network/interfaces is set up to give the Pi a static ip on start up. However, when connection is dropped the Pi won't re-establish a connection automatically. I have a script that restarts wlan0. However, the Raspberry Pi has a different ip address than the static ip given to it. This breaks the port forwarding I’ve done to access the Pi from outside the network.
It looks as if my interfaces is not set up quite right. The Pi can be accessed from two ip addresses within the network, one is the static address I defined while the other is not. When wlan0 is restarted, a dynamic ip address is given to the Pi, but not the static address.
Here is my /etc/network/interfaces:
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet manual
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.11
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid "ROUTER NAME"
wpa-psk "PASSWORD"
auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Here is the script I'm using to reset wlan0:
#!/bin/bash
SERVER=192.168.1.1 #Ping the router
ping -c2 ${SERVER} > /dev/null
#If the exits status from the ping is not 0 (failed)
if [$? != 0]
then
#Disable wlan0 and re-enable it
sleep 2
ifconfig wlan0 down
sleep 2
ifconfig wlan0 up
fi
Any help is appreciated! Thanks!
Edit:
After looking around with ideas found in this thread, I found /etc/init.d/networking restart does everything I need.So the new script is
#!/bin/bash
SERVER=192.168.1.1
ping -c2 ${SERVER} > /dev/null
if [ $?!=0 ]
then
/etc/init.d/networking restart
echo "Reconnecting!"
fi
I looked around a bit and it seems you may be able to make sure it is set in your wifi script after ifconfig wlan0 up (I've also had to implement such a script on every raspberry pi setup I've ever made due to wifi inconsistencies)
if [$? != 0]
then
#Disable wlan0 and re-enable it
sleep 2
ifconfig wlan0 down
sleep 2
ifconfig wlan0 up
ifconfig wlan0 192.168.1.11
fi
Though it should be noted that I personally have never set up a static ip on a pi, I use a reverse tunneling service so I never have to worry about port forwarding. My answer references this answer from the raspberrypi stackexchange site.
https://raspberrypi.stackexchange.com/questions/9678/static-ip-failing-for-wlan0
Let me know if that helps otherwise I can dig deeper into it.
According to feedback from the asker, the /etc/init.d/networking restart was the answer, read comments below.

Assigning static ip in linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I've tried to assign static ip to my raspberry computer, yet it doesn't assign it after rebooting. My /etc/networ/interfaces file looks like this:
auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
#iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
After rebooting and using ifconfig command it shows me that the address is different. What should I do to make it assign data from the file?
It's /etc/network/interfaces not /etc/networ/interfaces and you forgot to add:
auto eth0
iface eth0 inet static
You should do:
/etc/init.d/networking restart
or
ifdown eth0
ifup eth0
Instead of rebooting, Also make sure that 192.168.1.2 isn't used already.
Try changing
auto lo
to
auto lo eth0
As this will make ifup -a run during system startup configure eth0 as well. (see man interfaces).

I log into a machine using ssh with IP1. When logged in, the output of ifconfig/'ip addr' shows IP2. Why is IP1 and IP2 different?

I type:-
ssh root#10.2.4.xx
So, IP1 :- 10.2.4.xx
When logged into the machine, the output of
ifconfig
is:-
eth0 Link encap:Ethernet HWaddr fa:xx:xx:xx:xx:xx
inet addr:172.17.xx.xx Bcast:172.17.xx.xxx Mask:255.255.255.0
inet6 addr: fe80::xxxx:xxxx:xxxx:xxxx/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
.
.
.
So, IP2 is 172.17.xx.xx.
Shouldn't IP1 and IP2 be the same? Why are they different?
The most likely reason is that the computer you are logging to has two network interface cards, one (eth0) configured with IP1 and the other (probably eth1?) configured with IP2. The output of ifconfig should show both.
Other less likely reasons are:
your ssh config file .ssh/config has an entry which reads 'host 10.2.4.xx hostname 172.17.xx.xx`
your /etc/hosts has a line 10.2.4.xx 172.17.xx.xx
the .bashrc of root on IP1 contains ssh -t 172.17.xx.xx

nc -u 192.168.1.255 9999 fails

I am trying to broadcast to 192.168.1.255 which is my broadcast address. ifconfig says
eth0 Link encap:Ethernet HWaddr 50:e5:49:51:0b:cb
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::52e5:49ff:fe51:bcb/64 Scope:Link
but If i do nc -uv 192.168.1.255 9999 it reports
nc: connect to 192.168.1.255 port 9999 (udp) failed: Permission denied
but nc -uv 192.168.0.255 9999 works fine
Try using socat instead since some nc tools don't support UDP broadcasting.
echo "HELLO" | socat - UDP4-DATAGRAM:192.168.1.255:9999,broadcast

linux device driver for pure ipv6 device

I am currently designing a linux driver for a pure IPv6 driver. Is there any way to make the kernel module only support IPv6 and can only be assigned IPv6 address? What is the commands in linux to set the address?
Thanks
Adding IP:
Using ip command:
$sudo /sbin/ip -6 addr add 2001:0db8:0:f101::1/64 dev eth0
Using ifconfig command:
$sudo /sbin/ifconfig eth0 inet6 add 2001:0db8:0:f101::1/64
Deleting IP:
Using ip
$sudo /sbin/ip -6 addr del 2001:0db8:0:f101::1/64 dev eth0
Using ifconfig
$sudo /sbin/ifconfig eth0 inet6 del 2001:0db8:0:f101::1/64

Resources