Linux/Ubuntu faking a network connection - linux

I have a couple of programs that talk t each other through HTTP. I have a main program that is a HTTP server that acts as a browser for other programs to query.
Everything works fine if... I have an internet connection on my machine, but when I disconnect the cable, eth0 goes down and I can't connect to anything.
In windows all I need is a loopback network card and I am set.
In my ubuntu box (10.10) I still have lo connected with it's assigned IP but I can't force eth0 to go up.
How can I have a working connection without being connected?!
Can I fake a connection?
Cheers
André Moreira
some clarification, the first thing I am doing is trying to send a broadcast to discover what other apps are on the same network.
This is failing because the network is unreachable. Try to unplug you cable and ping to 255.255.255.255...
I guess that when I "solve this" everything will fall into place.

There is a loopback in Linux, and it has an IP address (like all IP based network interfaces).
Just connect to 127.0.0.1, or localhost if your network configuration hasn't been customized to not follow the standard.
Often the alias for the loopback interface is lo and here is a typical entry from 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:16436 Metric:1
RX packets:6026819 errors:0 dropped:0 overruns:0 frame:0
TX packets:6026819 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2106315659 (1.9 GiB) TX bytes:2106315659 (1.9 GiB)

Related

How to get IP adress of machine(on Linux) in AP mode?

I am Configuring my board in Wi-Fi AP mode. I am able to see wlan AP interface using ifconfig
ifconfig wlan1
wlan1 Link encap:Ethernet HWaddr 74:DA:EA:C2:63:17
inet addr:192.168.43.1 Bcast:192.168.43.255 Mask:255.255.255.0
inet6 addr: fe80::76da:eaff:fec2:6317%767480/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:62 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:12808 (12.5 KiB)
I have Linux 4.4 running on my board. Is there any API through which i can get the ip address of board i.e. 192.168.43.1 .
I want to write a c application which will use this IP address. Thanks
use ioctl with SIOCGIFADDR will help.
In the case of linux, there are multiple ways to get the IP address of interface using a C program.
ioctl - This is supported in linux for configuring or fetching information about the network devices. You can use ioctl commands that operate on interfaces such as SIOCGIFADDR for fetching IP address of interface and SIOCGIFNETMASK to get the interface netmask.
getifaddrs - This can be used for fetching the IP address of the interface. Refer to the link http://man7.org/linux/man-pages/man3/getifaddrs.3.html which carries a wonderful example.

Python 3 - Cannot receive IPv6 packets (UDP - linux)

I have a script that is trying to receive IPv6 packets, but it fails to receive any.
First off, here is my ethernet configuration from ifconfig.
eth1 Link encap:Ethernet HWaddr f8:b1:56:9a:cf:ef
inet addr:192.168.1.90 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::fab1:56ff:fe9a:cfef/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:751359199 errors:38 dropped:10874 overruns:0 frame:35
TX packets:23407 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1033523557150 (1.0 TB) TX bytes:2002869 (2.0 MB)
Interrupt:20 Memory:ef400000-ef420000
I have two network cards, but am using one for internet and one for testing. The second card is connect to a device that sends ethernet packets. I am configuring that device to send IPv6 packets to address fe80::fab1:56ff:fe9a:cfef and port 46780 (however, I can configure it to send to any IPv6 address and any port). I wrote a python script to receive these packets, but I either get an error, or my script doesn't find the packets. I confirmed these packets through wireshark, and through using a raw python socket.
Here is a list of things I have tried and the various errors/problems I encounter.
If I bind to address "::1", I am able to bind to the address. However, I never receive any IPv6 packets.
I tried using socket.getaddrinfo() and then use the returned information and bind to that, however when I try to do so I get the error "Invalid argument"
info = socket.getaddrinfo(host_ipv6_addr, port_num, socket.AF_INET6,
socket.SOCK_DGRAM, 0, socket.AI_PASSIVE)
rtp_socket.bind(info[0][4])
socket.getaddrinfo returns [(10, 2, 17, '', ('fe80::fab1:56ff:fe9a:cfef', 46780, 0, 0))]
If I try to bind directly to my IPv6 address, I also received "Invalid argument". However, when I changed the scope from 0 to 5, I instead received the error "Cannot assign request address".
rtp_socket.bind( (host_ipv6_addr, port_num, 0, 5))
Any insight would be greatly appreciated. I'm guessing at this point that I don't have my ethernet card setup properly or something.
UPDATE:
Using Michael Hampton's answer, I solved my problem by using the information from socket.getaddrinfo with the IP address being "fe80::fab1:56ff:fe9a:cfef%eth1" and sticking the results into rtp_socket.bind(). The scope ID went from 0 to 3.
You're trying to bind to a link-local address but you have forgotten to include the scope ID (in this case, %eth1).
So you should be binding to address fe80::fab1:56ff:fe9a:cfef%eth1.

dhcpv6 returning bad subnet

I have IPv6 on a linux machine and my network and it works. Now I want to set up DHCP for it. I set up the isc-dhcp-server and configured the subnet.
Another linux machine (both debian 7) acts as test-client and gets the IP, but not in the range configured, and, much worse, gets a /64 subnet and not a /80.
Since the IP pool available on the router is already a subset of the /64 assigned to another upstream-machine, I need a smaller subnet. I cannot allow it to be /64.
Config of dhcp server:
subnet6 2a01:4f8:202:6106:acda::/80 {
range6 2a01:4f8:202:6106:acda:f000::/84;
option dhcp6.name-servers 2a01:4f8:202:6106::2;
prefix6 2a01:4f8:202:6106:acda:c000:: 2a01:4f8:202:6106:acda:f000:: /84;
}
ifconfig output on client:
debian#arm:~$ sudo ifconfig
[sudo] password for debian:
eth0 Link encap:Ethernet HWaddr c8:a0:30:ae:48:24
inet addr:192.168.0.104 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::caa0:30ff:feae:4824/64 Scope:Link
inet6 addr: 2a01:4f8:202:6106:acda:ff2f:452c:b7b5/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:185 errors:0 dropped:0 overruns:0 frame:0
TX packets:201 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:18222 (17.7 KiB) TX bytes:23159 (22.6 KiB)
Interrupt:56
A windows-7 machine also connected does not get an IPv6 address at all.
config of the radvd on the server (in case it matters)
interface eth0 {
AdvSendAdvert on;
prefix 2a01:4f8:202:6106:acda::/80 {
AdvOnLink on;
AdvAutonomous on;
AdvRouterAddr on;
};
route 2000::/3
{
};
};
What's wrong? Why is this not working? Is the bad subnet-size a bug in the server? Or the client?
Result of the bad subnet-size is that for example the nameserver, 2a01:4f8:202:6106::2 , in the 64-bit range, is not reachable. The client thinks it should be on the lan segment and tries to get the link-local IPv6 and the ethernet MAC of it and fails. It needs to go via the router. When I set the subnet manually to /80 everything works fine.
First of course the general warning: using non-/64 subnet sizes will break things. Your ISP should really give you a decent amount of address space to work with, like a /48 or a /56. You can then route /64s out of that wherever you want.
Then you have to look at how your ISP gives you your current /64. If they route it to a LAN that is connected to your server's eth0 interface then there is nothing much you can do except bridging or proxy-ND because you have to make it look like everything is directly connected to that LAN. Both methods have their own complications.
If you are bridging to a LAN managed by your ISP then you shouldn't run anything like radvd or dhcpd because you'll interfere with your ISP.
If you are using proxy-ND or your ISP routes the /64 to your server (so you have a different IPv6 address on your server's interface to the ISP and the ISP routes the /64 to that interface) then you should indeed run radvd and dhcpd but only on the internal interface, not towards your ISP.
Back to your RA+DHCPv6 setup because that part of your question is easy to answer. There are three things wrong with your radvd setup (so, yes, it matters a lot :)
First you cannot do SLAAC (StateLess Address Auto Configuration) on anything except a /64 so you'll have to turn AdvAutonomous off. Then you have to tell the clients that a managed (stateful) DHCPv6 server is available so turn the AdvManagedFlag on. And the route 2000::/3 is also unnecessary. You are advertising that you are the default gateway and this more-specific doesn't add anything useful.
interface eth1 {
AdvSendAdvert on;
AdvManagedFlag on;
prefix 2a01:4f8:202:6106:acda::/80 {
AdvOnLink on;
AdvAutonomous off;
AdvRouterAddr on;
};
};

how to find which packets got dropped

I'm getting thousands of dropped packages from a Broadcom Network Card:
eth1 Link encap:Ethernet HWaddr 01:27:B0:14:DA:FE
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:2746252626 errors:0 dropped:1151734 overruns:0 frame:0
TX packets:4109502155 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:427998700000 (408171.3 Mb) TX bytes:3530782240047 (3367216.3 Mb)
Interrupt:40 Memory:d8000000-d8012700
Here is the installed version:
filename: /lib/modules/2.6.27.54-0.2-default/kernel/drivers/net/bnx2.ko
version: 1.8.0
license: GPL
description: Broadcom NetXtreme II BCM5706/5708/5709 Driver
The packets get dropped in bulks ranging from 500 to 5000 packets several times an hour. The Server (running Postgres) is running fine - just the dropps are annoying.
After trying lots of different things, I'm asking: How may I find out where the packets came from and why were they dropped?
A dropped packet means that the buffer that is used to store the packet for forwarding/processing is full. The act of looking into the packet's data for information implies that you have the data to look at in the first place (which you don't, because there was no room to store it).
A nice way around this, so you can see what data is being dropped, is to look through a dump of your traffic for the TCP retransmission requests leaving your server. When a TCP packet is missing, for whatever reason, your server is going to ask for it to be re-sent. The retransmit will give you the conversation context that you're looking for.
I'd actually suggest taking a look at the switch/router that your server is connected to. It will be able to give you a nice idea of the loss and throughput over the interface to your server, letting you diagnose, for example, if your card is too slow for the wire.
EDIT
This blog post cites a tool called dropwatch, which may give you some clues as well.
You may ran into https://www.novell.com/support/kb/doc.php?id=7007165.
quote:
Beginning with kernel 2.6.37, it has been changed the meaning of dropped packet count. Before, dropped packets was most likely due to an error. Now, the rx_dropped counter shows statistics for dropped frames because of:
Softnet backlog full -- (Measured from /proc/net/softnet_stat)
Bad / Unintended VLAN tags
Unknown / Unregistered protocols
IPv6 frames when the server is not configured for IPv6
If any frames meet those conditions, they are dropped before the protocol stack and the rx_dropped counter is incremented.
(For the benefit of those that come to this via a search) I've seen the same problem (also with a bnx2 module, IIRC).
You might try turning off the irqbalance service. In my case, it completely stopped the solution.
Please also note that not so long ago, there were plenty of updates (RHEL 6) for irqbalance. Firmware updates should also be checked for both main system and the ethernet board(s).
We were seeing this only a very large subnet with a very large amount of broadcast/multicast activity. We weren't seeing this on the same equipment on a less noisy -- but still very active -- part of the network.
Potentially, setting the ethernet ring buffer size for the NIC can also be of use. I know there were some alterations for sysctl on that busy network...

Any tool to measure progressive download of video?

Can you suggest a tool(Linux based) to measure dynamically the amount of data being downloaded or buffered
by a video(progressive download like Youtube video) that is being played in a browser(Mozilla).
ifconfig eth0:
eth0 Link encap:Ethernet HWaddr ...
inet ...
inet6 ...
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9278084 errors:0 dropped:0 overruns:0 frame:0
TX packets:4290251 errors:0 dropped:103 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10351665680 (10.3 GB) TX bytes:485621573 (485.6 MB)
Interrupt:45 Base address:0xc000
Make sure that the browser is the only thing that's running and the measurement should be pretty accurate.
There are other tools like lsof(8) but those don't work well with browsers since the browser doesn't have to keep a connection open, so the output will change all the time and you'll lose data when the connection is closed.
Or you can install a local proxy server like squid and enable statistics for it.

Resources