Raspberry Pi configured for static IP also gets a DHCP IP - linux

I've configured my Raspberry Pi for static IP. My /etc/network/interfaces looks like this:
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
Yet for some strange reason, every time I reboot my Pi or my router, my Pi gets the requested IP (192.168.1.2) but ALSO a DHCP address (192.168.1.18). So my Pi has two addresses.
Of course, this isn't necessarily a problem, I just think it's strange. Am I doing something wrong? Or not enough? My router is almost completely locked down for management, but I can enter static IPs for devices - is this necessary, if I configure the Pi to do it?
The dynamic address isn't apparent in ifconfig:
eth0 Link encap:Ethernet HWaddr b8:27:eb:5d:87:71
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:236957 errors:0 dropped:34 overruns:0 frame:0
TX packets:260738 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:35215632 (33.5 MiB) TX bytes:70023369 (66.7 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:27258 errors:0 dropped:0 overruns:0 frame:0
TX packets:27258 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3397312 (3.2 MiB) TX bytes:3397312 (3.2 MiB)
yet I can ping, ssh and everything on .18 as well.

Since you can add multiple IP addresses to the interface eth0 as noted above, I believe the solution to your problem is to remove the auto eth0 line from your /etc/network/interfaces file.

The IP address attached to interface eth0 can be viewed by ip addr. May be eth0 has two IP address configured 192.168.1.2 and 192.168.1.18.
Also you can add multiple IP address to interface eth0 through
sudo ip addr add <IP address> dev eth0
If you dont want IP address 192.168.1.18 you can remove it by
sudo ip addr del 192.168.1.18 dev eth0

Related

How to set multiple IP Address on a raspberry pi 3

I brought a USB to Ethernet adapter, now I connected that to USB on raspberry pi 3 on one end and to the ethernet on the other end (So that I can set two IP address for my pi).
Note: I am also using my Ethernet port on Raspberry Pi 3
If I disconnect my Ethernet port and connect only through USB to Ethernet Adapter, I couldn't communicate. I assume that there is no communication happening with my USB-Ethernet Adapter. I want both the IP addresses work at a time
Then I've changed the /etc/network/interfaces file as shown below:
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.147.146
netmask 255.255.255.0
gateway 192.168.147.255
auto eth0:0
allow-hotplug eth0:0
iface eth0:0 inet static
address 192.168.147.145
netmask 255.255.255.0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
This is my output from ifconfig from the terminal:
eth0 Link encap:Ethernet HWaddr b8:27:eb:0d:2b:28
inet addr:192.168.147.146 Bcast:192.168.147.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:71565 errors:0 dropped:928 overruns:0 frame:0
TX packets:17901546 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6283723 (5.9 MiB) TX bytes:1220265483 (1.1 GiB)
eth0:0 Link encap:Ethernet HWaddr b8:27:eb:0d:2b:28
inet addr:192.168.147.145 Bcast:192.168.147.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:910 errors:0 dropped:0 overruns:0 frame:0
TX packets:910 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:79976 (78.1 KiB) TX bytes:79976 (78.1 KiB)
Please let me know your suggestions.....
Your USB to Ethernet adaptor is a physical network adaptor however you have set it up as if it were a virtual network adaptor.
Try changing eth0:0 to eth1 in your /etc/network/interfaces file
Your code should look something like this:
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.147.146
netmask 255.255.255.0
gateway 192.168.147.255
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.147.145
netmask 255.255.255.0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Can't ping two adhoc wireless lop tops (linux)

I want to run an ad-hoc wireless on two lop tops that both of them have Linux OS. I use this for creating ad-hoc network.(I have stopped Network Manager before it)
sudo ifconfig wlan0 down
sudo iwconfig wlan0 mode ad-hoc essid test-adhoc channel 3
sudo ifconfig wlan0 up
sudo ifconfig wlan0 192.168.1.1 netmask 255.255.255.0
My ifconfig:
ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:25388 errors:0 dropped:0 overruns:0 frame:0
TX packets:25388 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3916018 (3.9 MB) TX bytes:3916018 (3.9 MB)
vmnet1 Link encap:Ethernet HWaddr 00:50:56:c0:00:01
inet addr:192.168.237.1 Bcast:192.168.237.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:fec0:1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:505 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
vmnet8 Link encap:Ethernet HWaddr 00:50:56:c0:00:08
inet addr:172.16.62.1 Bcast:172.16.62.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:fec0:8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:504 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr ac:72:89:1b:19:76
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::ae72:89ff:fe1b:1976/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1543085 errors:0 dropped:27 overruns:0 frame:0
TX packets:19353 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:183406489 (183.4 MB) TX bytes:3741745 (3.7 MB)
And iwconfig
vmnet8 no wireless extensions.
eth0 no wireless extensions.
lo no wireless extensions.
wlan0 IEEE 802.11bgn ESSID:"test-adhoc"
Mode:Ad-Hoc Frequency:2.422 GHz Cell: A2:A3:E3:9B:6A:FA
Tx-Power=15 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Power Management:off
vmnet1 no wireless extensions.
IP for first Lop top is <192.168.1.1> and for second one is <192.168.1.2>. I checked the route:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.62.0 * 255.255.255.0 U 0 0 0 vmnet8
192.168.1.0 * 255.255.255.0 U 0 0 0 wlan0
192.168.237.0 * 255.255.255.0 U 0 0 0 vmnet1
But when i ping one from other:
ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
From 192.168.1.1 icmp_seq=1 Destination Host Unreachable
From 192.168.1.1 icmp_seq=2 Destination Host Unreachable
From 192.168.1.1 icmp_seq=3 Destination Host Unreachable
From 192.168.1.1 icmp_seq=4 Destination Host Unreachable
From 192.168.1.1 icmp_seq=5 Destination Host Unreachable
From 192.168.1.1 icmp_seq=6 Destination Host Unreachable
what should i do? My system is Ubuntu 14.04.
I just change my approach. In this tutorial the second method is not working.
In the first method just don't use the "auto wlan0". (If you do you will connect to another network, possibly)

How to configure 2 lan cards on ubuntu

I want to configure 2 lan cards on 1 pc such that it seems that both are connected on different networks.
Also i want the gateway of one lan card be the ip address of the other so that the traffic of one passes through the second. I am applying mitmproxy on my pc to monitor my own traffic.
I am new to ubuntu as well as networking. So if anything i have said is wrong, please do correct me.
ifconfig -a
eth0
Link encap:Ethernet HWaddr 00:1c:c0:0d:85:38
inet addr:10.0.0.55 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::21c:c0ff:fe0d:8538/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8094 errors:0 dropped:0 overruns:0 frame:0
TX packets:7628 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6890690 (6.8 MB) TX bytes:1094128 (1.0 MB)
eth1
Link encap:Ethernet HWaddr 10:fe:ed:01:ce:34
inet addr:10.0.0.95 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::12fe:edff:fe01:ce34/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2338 errors:0 dropped:0 overruns:0 frame:0
TX packets:2322 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1303961 (1.3 MB) TX bytes:256352 (256.3 KB)
lo
Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:3849 errors:0 dropped:0 overruns:0 frame:0
TX packets:3849 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1008514 (1.0 MB) TX bytes:1008514 (1.0 MB)
Thanks
You can try iptables to redirect traffic from 1 interface to other.
iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 80 -j REDIRECT --to-ports 8080
will redirect all traffic coming on interface ppp0 on port 80 to port 8080 , where you can run an mitm proxy. Your mitm proxy can use eth0 to forward traffic out.
You might get a better response on serverfault or superuser.
In order to put two different network cards on two different networks you need to assign their IP's properly.
Based on the fact that you are using Net Mask of 255.255.255.0 setting one network card to have IP 10.0.0.1 and second to 10.0.1.1 would put them on two seperate networks. Netmask of 255.255.255.0 defines that your network can contain all IP's which have same first three numbers and fourth from 0 to 255. So if you change one of the first three numbers you put your network card on another network.
As for gateway it must be on the same network that your lan card is. So setting two network card to be on two seperate networks and then setting one lans card gateway to be the other network card won't work. Athleast not until you bridge the two networks together, but that won't prevent computers from one network to access computers on another which I belive is what you wanna do.

wireshark doesn't display icmp traffic between tow logical interafce

I add tow logical interfaces for test with the following commands :
# set link on physical Device Up
sudo ip link set up dev eth0
# create logical Interfaces
sudo ip link add link eth0 dev meth0 address 00:00:8F:00:00:02 type macvlan
sudo ip link add link meth0 dev meth1 address 00:00:8F:00:00:03 type macvlan
# order IP Addresses and Link
sudo ip addr add 192.168.56.5/26 dev meth0
sudo ip addr add 192.168.56.6/26 dev meth1
sudo ip link set up dev meth0
sudo ip link set up dev meth1
ifconfig
meth0 Link encap:Ethernet HWaddr 00:00:8f:00:00:02
inet addr:192.168.56.5 Bcast:0.0.0.0 Mask:255.255.255.192
inet6 addr: fe80::200:8fff:fe00:2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:35749 errors:0 dropped:47 overruns:0 frame:0
TX packets:131 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3830628 (3.8 MB) TX bytes:15278 (15.2 KB)
meth1 Link encap:Ethernet HWaddr 00:00:8f:00:00:03
inet addr:192.168.56.6 Bcast:0.0.0.0 Mask:255.255.255.192
inet6 addr: fe80::200:8fff:fe00:3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:35749 errors:0 dropped:47 overruns:0 frame:0
TX packets:115 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3830628 (3.8 MB) TX bytes:14942 (14.9 KB)
I run "wireshark" to test traffic between meth0 and meth1 ,
so I execute ping 192.168.56.6 to generate icmp traffic but this traffic doesn't appear in wireshark .
there is a a problem in wireshark with logical interface ?
Is there a problem in wireshark with logical interface?
Probably not. You'll probably see the same problem with tcpdump, netsniff-ng, or anything else that uses PF_PACKET sockets for sniffing on Linux (Linux in general, not just Ubuntu in particular, or even Ubuntu, Debian, and other Debian-derived distributions).
Given that those are two logical interfaces on the same machine, traffic between them will not go onto the Ethernet - no Ethernet adapters I know of will receive packets that they transmit, so if the packet were sent on the Ethernet the host wouldn't see it, and there wouldn't be any point in wasting network bandwidth by putting that traffic on the network even if the Ethernet adapter would see its own traffic.
So if you're capturing on eth0, you might not see the traffic. Try capturing on lo instead.

Connect embedded system to host via ethernet over a switch

I have a arm platform with gigabit ethernet that I would like to connect to my ubuntu machine
to test the ethernet ports.
Networking is not my strong suit.
I've modified /etc/network/interfaces on the embedded system thusly:
# Configure Loopback
auto lo
iface lo inet loopback
#auto eth0
#iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.0
And on my ubuntu machine I have set (through the network connections window):
IP: 192.168.1.1
netmask: 255.255.255.0
gateway: 192.168.1.0
When I test the connection, no connection is recognized on the arm system.
The eth0 port produces this output:
eth0: link up, 10 Mb/s, half duplex, flow control disabled
ip: RTNETLINK answers: Invalid argument
ifconfig displays:
# ifconfig
eth0 Link encap:Ethernet HWaddr 02:50:43:C5:C5:75
inet addr:192.168.1.2 Bcast:0.0.0.0 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:11
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Can anyone point out my most likely obvious mistake?
Let me know if I need to provide more information.
EDIT: I'm running busybox 1.18.5 on the embedded system.
EDIT 2:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
This is bad
auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.0
192.168.1.0 is your network address. For sure it cannot be your gateway. Usually you have configuration like this
auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255
where the latter two can automatically be calculated from the address and the netmask and are therefore not written in the config file

Resources