Why I can't connect the eth0 with putty? - linux

eth0 Link encap:Ethernet HWaddr 06:20:08:46:CD:C7
inet addr:172.26.26.60 Bcast:172.26.26.63 Mask:255.255.255.192
inet6 addr: fe80::420:8ff:fe46:cdc7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1
RX packets:1577 errors:0 dropped:0 overruns:0 frame:0
TX packets:1340 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:141738 (138.4 KiB) TX bytes:215770 (210.7 KiB)
Interrupt:165
eth1 Link encap:Ethernet HWaddr 06:81:8C:00:F4:F2
inet addr:172.26.26.37 Bcast:172.26.26.63 Mask:255.255.255.192
inet6 addr: fe80::481:8cff:fe00:f4f2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1
RX packets:269 errors:0 dropped:0 overruns:0 frame:0
TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16216 (15.8 KiB) TX bytes:8921 (8.7 KiB)
Interrupt:164
the server is a LAMP environment. I use DHCP mode to add a eth1, ifconfig shows as the above. and I can't connect to the eth0 with ip 172.26.26.60 I can only connect to the eth1 with 172.26.26.37 with putty. is set but not working.
I want to know why I can't connect to the 172.26.26.60?
edit:
route -n
it outputs like below:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.26.26.0 0.0.0.0 255.255.255.192 U 0 0 0 eth0
172.26.26.0 0.0.0.0 255.255.255.192 U 0 0 0 eth1
0.0.0.0 172.26.26.1 0.0.0.0 UG 0 0 0 eth1

Check your Ssh server config. It might only be listening on one address. netstat -an | grep 22 | grep LISTEN should show you which address you're listening on.

Step 0 - ping, check cables, etc.
Step 1 - check if sshd is really listening on 0.0.0.0. Otherwise it's only available on the corresponding interface.
Step 2 - check iptables -nvL
Step 3 - check route -n

Related

How to display IP address of all interface for a shell script?

I want to display all network interface for a script, including vip.
~]$ /sbin/ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:90:88:37
inet addr:192.168.1.15 Bcast:192.168.1.31 Mask:255.255.255.224
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9786341 errors:0 dropped:152 overruns:0 frame:0
TX packets:10162602 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6846599961 (6529.4 Mb) TX bytes:2951709145 (2814.9 Mb)
eth1 Link encap:Ethernet HWaddr 00:50:56:90:E1:2E
inet addr:25.10.100.15 Bcast:25.10.100.31 Mask:255.255.255.224
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:42436 errors:0 dropped:150 overruns:0 frame:0
TX packets:35 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5484037 (5.2 Mb) TX bytes:2446 (2.3 Kb)
Like this
eth0 00:50:56:90:88:37 192.168.1.15 MTU:1500
eth0 00:50:56:90:E1:2E 25.10.100.15 MTU:1500
Please help to get this
Thanks in advance
You can use awk and set the record separator to an empty line, for example this
/sbin/ifconfig | awk -v RS='' '{print $14}'
will print
MTU:1500
MTU:1500
so just pick the fields you want.

Getting a substring in bash script

I was trying to get a substring in a bash script however the way I did is not a good solution. I'm parsing the response of "ifconfig" command and trying to get the first network interface name.
result of ifconfig:
eth0 Link encap:Ethernet HWaddr b8:27:eb:6d:a1:92
UP BROADCAST 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)
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:73 errors:0 dropped:0 overruns:0 frame:0
TX packets:73 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7099 (6.9 KiB) TX bytes:7099 (6.9 KiB)
wlan0 Link encap:UNSPEC HWaddr ****
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:792698 errors:0 dropped:792552 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:219274179 (209.1 MiB) TX bytes:0 (0.0 B)
wlan5 Link encap:Ethernet HWaddr ****
inet addr:**** Bcast:**** Mask:****
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:48934 errors:0 dropped:3422 overruns:0 frame:0
TX packets:21217 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14458518 (13.7 MiB) TX bytes:2692948 (2.5 MiB)
getting first interface name which is wlan0
conf=`ifconfig`
net=${conf:670:6}
I didn't understand but position sometimes changes this is why i can't use index 670. Wlan0 can be wlan1,wlan2 and so on... I can't specifically search for wlan0. Any suggestions?
GNU awk
ifconfig | awk -vRS= '!/^(eth0|lo)/{print $1;exit}'
Skips etho and lo blocks and prints the first field of the next, then quits.
At first I thought the question was to get all the wlans and answered this:
$ ifconfig | egrep -A6 '^wlan[0-9]:'
but then it was pointed out that this was GNU, not BSD so I should have said
$ ifconfig | egrep -A6 '^wlan[0-9]'
(no colons). Then it was clarified that only the first one was needed, so perhaps
$ ifconfig | head -n 6
is a better answer?
If there are not exactly 6 lines in any description, then this isn't a very good answer.
Another approach is this:
$ ifconfig eth0 || ifconfig lo0 || ifconfig wlan0 || ifconfig wlan1
and so on. The || means if the first part fails, try the second. You'll get error messages until you hit one that works.
Now here is something better!
$ ifconfig | head -n 1
will give you the first one. Take that line, cut out the first thing on the line, then pass that to ifconfig. This should work on Linux:
$ ifconfig | head -n 1 | awk '{print $1}' | xargs ifconfig
What about something like?
ifconfig | grep -v "^ " "eth0" "lo" | head -1 | cut -c1-6
Have not a Linux pc on which to test it, though.
Basically, i just extract all the lines which do have the name of a net interface, removing all the eth0 and lo stuff, then I get the first one and get only the chars I need

Linux pattern to substring the no of RX Packets from an interface of ifconfig

I need a linux script to get the number of RX packets form an interface when call ifconfig.
EXAMPLE:
this is ifconfig :
eth0 Link encap:Ethernet HWaddr 08:00:27:cc:94:d5
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fecc:94d5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:71460 errors:0 dropped:0 overruns:0 frame:0
TX packets:46999 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:67766944 (67.7 MB) TX bytes:5110629 (5.1 MB)
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:4587 errors:0 dropped:0 overruns:0 frame:0
TX packets:4587 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:471078 (471.0 KB) TX bytes:471078 (471.0 KB)
when calling the script :
./getRXpackets eth0
the output will be : 71460
the same for the other interface
./getRXpackets lo
the output will be : 4587
\K discards the previously characters from printing at the final. \K keeps the text matched so far out of the overall regex match.
Code:
#!/bin/bash
var=$(ifconfig $1 | grep -oP 'RX packets:\K\d+')
echo $var;
Run the above script by,
bash ./script eth0

zolertia z1 connection with tunslip for webserver

I want to install a webserver on my zolertia z1 sensor. I followed step here : http://wismote.org/doku.php?id=development:sample_code
When i run tunslip program like this :
"sudo ./tunslip -B 115200 -s /dev/ttyUSB0 192.168.1.1 255.255.255.0 "
Results are :
slip started on ``/dev/ttyUSB0''
opened device ``/dev/tun0''
ifconfig tun0 inet `hostname` up
route add -net 192.168.1.0 netmask 255.255.255.0 dev tun0
ifconfig tun0
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:127.0.1.1 P-t-P:127.0.1.1 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP 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:500
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
The route on tun0 is opened but he doesn't detect my sensor connected with serial line. There no "route add -net 192.168.1.2 netmask 255.255.255.255 dev tun0" at end and i don't know why. I don't know if i must change the flag for a TAP or TUN device ?!
if i try to login on my sensor with "make login". it works fine. the program is
correctly installed on this.
I tried this on a virtual image with contiki and on Ubuntu 12.04.4 LTS x86_64. I have the same result on both OS.
Maybe you've to change your BaudRate which it's used to be arround 38.400 bauds on motes z1 Zolertia.
sudo ./tunslip -B 38400 -s /dev/ttyUSB0 192.168.1.1 255.255.255.0

ip route src not working

1I need to use several IPs on interface in Linux, and switch it, but it's not working.
for example:
# ifconfig
eth0 Link encap:Ethernet HWaddr 90:2b:34:33:80:65
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::922b:34ff:fe33:8065/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13220652 errors:0 dropped:32864 overruns:0 frame:0
TX packets:8296620 errors:0 dropped:0 overruns:0 carrier:1
collisions:0 txqueuelen:1000
RX bytes:16166162509 (16.1 GB) TX bytes:2186645852 (2.1 GB)
Interrupt:48
eth0:1 Link encap:Ethernet HWaddr 90:2b:34:33:80:65
inet addr:192.168.1.99 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:48
lo Link encap:Локальная петля (Loopback)
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:276685 errors:0 dropped:0 overruns:0 frame:0
TX packets:276685 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:21387439 (21.3 MB) TX bytes:21387439 (21.3 MB)
# ip route
169.254.0.0/16 dev eth0 scope link metric 1000
192.168.1.0/24 dev eth0 scope link src 192.168.1.99
# ping 192.168.1.50
PING 192.168.1.50 (192.168.1.50) 56(84) bytes of data.
64 bytes from 192.168.1.50: icmp_req=1 ttl=255 time=1.21 ms
64 bytes from 192.168.1.50: icmp_req=2 ttl=255 time=1.07 ms
64 bytes from 192.168.1.50: icmp_req=3 ttl=255 time=1.05 ms
and then i use Curl
# curl 192.168.1.50
and tcpdump:
13:24:02.009094 IP 192.168.1.1 > 192.168.1.50: ICMP echo request, id 8919, seq 347, length 64
E..T..#.#..%.......2...s"..[...P....q#...................... !"#$%&'()*+,-./01234567
13:24:02.010087 IP 192.168.1.50 > 192.168.1.1: ICMP echo reply, id 8919, seq 347, length 64
E..T...........2.......s"..[...P....q#...................... !"#$%&'()*+,-./01234567
13:43:40.006264 IP 192.168.1.1.48275 > 192.168.1.50.80: Flags [S], seq 3496592766, win 14600, options [mss 1460,sackOK,TS val 15698502 ecr 0,nop,wscale 7], length 0
E..<O8#.#.h........2...P.i.~......9............
...F........
13:43:40.007663 IP 192.168.1.50.80 > 192.168.1.1.48275: Flags [S.], seq 3006420619, ack 3496592767, win 5792, options [mss 1460,sackOK,TS val 151247914 ecr 15698502,nop,wscale 0], length 0
E..<..#.#..8...2.....P...2V..i.................
..*...F....
and source ip is still 192.168.1.1, what am i doing wrong?
UPD: BTW, just tryed same thing on Ubuntu 10.04 with 2.6.32 kernel, everything works good, and you even dont need to add "-I" to "ping" command, it seams in my kernel (3.2.0) somebody broken this feature.
The src option only affects packets whose source address is chosen by the operating system. The ping program chooses its own source address. If you want to influence its choice, use the -I or -B options. If you want to see if your src option is working, make a TCP connection or send a UDP datagram.
try adding a specific route like below:
ip route add 192.168.1.50/32 dev eth0 proto static src 192.168.1.99
this should result in any traffic to 192.168.1.50 being sent with a src-ip of 192.168.1.99...instead of default 192.168.1.1

Resources