I am testing a simple multicast application on linux. I got it working on my pc by doing the following:
disabling the firewall
running the command route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
if you are interested in the details, see this post
why are these two steps required? is there an alternative.
i am testing the code on localhost.
on another pc I tried running the program after disabling the firewall. it did not work.
when I run the route command I get the following message
route: netmask 0fffffff doesn't make sense with host route
Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables
route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.
route {-h|--help} [<AF>] Detailed usage syntax for specified AF.
route {-V|--version} Display version/author and exit.
-v, --verbose be verbose
-n, --numeric don't resolve names
-e, --extend display other/more information
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
<AF>=Use '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
what is the solution?
got it to work without the route command.
just some firewall configuration problem.
i saw this recommendation to use route command for running ping on a multicast address. it is not required here.
Related
I've two nic (eth0/eth1) sending data to a router.
Only one is sending data at a time. I also need a static conf that doesn't change regarding if the NIC are up/down.
If I down eth0, I expect eth1 to make the job.
But destroying eth0 destroy also my default route to the router. So I'm done.
Adding 2 default route seem to work by hand, but I don't want this solution.
So I've tried to add "full" route for eth0 and eth1?
By hand it work but I failed to add them in route-eth0 and route-eth1.
$cat route-eth0
178.12.34.240 via 10.0.10.1 dev eth0
$cat route-eth1
178.12.34.240 via 10.0.10.1 dev eth1
$service network restart
...
Bringing up interface eth1:
Determining IP information for eth1... done.
RTNETLINK answers: File exists
...
$route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
178.12.34.240 10.00.10.1 255.255.255.255 UGH 0 0 0 eth0
...
As you can see route for eth1 failed to be applied. For sure because of the File exist error.
Question:
What is the conf to set to always have correct route whatever the NIC are up or down.
Or another best practice ? What about VIP?
Yes, Ron metric is the answer. But I did it on a static route.
It seems having several default route should be banned.
$cat route-eth0
178.12.34.240 via 10.0.10.1 metric 1 dev eth0
$cat route-eth1
178.12.34.240 via 10.0.10.1 metric 2 dev eth1
I have setup a Debian guest and I am messing around with it to learn more about VirtualBox, Debian, and later after that is done I'll be messing around with a NodeJS server on it.
After a while I noticed I couldn't do some things with it when I had a Bridged adapter setup for the VM. NPM would not install packages because it timed out. I tried running "w3m google.com" and even looked up google.com's ip to check for a DNS issue.
No matter what, I cannot connect to any form of internet. But I can ping anything just fine. I can ping google, npmjs.org, etc.
Thanks for the assistance.
Update: I have been working on this more today, Newer router, asus, I read that people were having issues with belkin routers with bridged adapters so I switched, the asus is new anyways.
The host is connected via ethernet wire.
The VM shows up on the router just fine, And I connect to that device with the IP given by the router just fine. but I still cannot connect to google.com or anything.
This is too long to explain in a comment. Below is how the bridged adapter works.
Yet, if you can ping from the guest debian that means some form of DHCP happened and you must have and IP (which is a different IP from the host machine). I'd check router configuration to see if you're not allowing/disallowing specific MACs and/or IPs from the usage of TCP/UDP protocols (that is a measure some people use on their routers).
Bridged adapter
A bridged adapter on VirtualBox simulates as if there was a bridge (well it is easier to think of this as a hub) on the cable connection to your (host) actual machine. Even if the connection is over wireless the simulation is similar.
For (almost) all purposes the guest (debian) and the router the host machine is connected to are connected directly. Have separate MAC, separate IP, they even give separate ARP requests.
router <---> host machine running VirtualBox
^
|
+-----> guest machine running Debian
This is done by sending packets with a different hardware address (you can configure the hardware address in the adapter).
You need to configure the guest system (Debian) to connect to the network as if it was a separate machine. For example, if you use a WPA connection from the host machine you need to configure WPA (including the username and password) in the guest machine.
I am not an expert, but after some research I could solve a similar problem. I have a Mac hosting a Debian server. I used Bridged Adapter on interface en0 in my Mac.
1) My Mac is running on 192.168.10.101. I know that because I run the command:
ifconfig -a
and the interface en0 shows that IP
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 6c:40:08:98:72:4c
inet6 fe80::6e40:8ff:fe98:724c%en0 prefixlen 64 scopeid 0x4
inet 192.168.10.101 netmask 0xffffff00 broadcast 192.168.10.255
2) Running netstat command at my Mac:
netstat -nr
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.10.1 UGSc 296 142 en0
I see that the Mac Gateway is on 192.168.10.1
3) Mac and Debian must be in the same segment as the Gateway, I mean 192.168.10.xxx. So I decided that my Debian must run on the static IP 192.168.10.115.
I edited /etc/network/interfaces file at my Debian server to look this way:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.10.115
netmask 255.255.255.0
gateway 192.168.10.1
dns-nameservers 8.8.8.8 192.168.10.1
Then I did ping from my Mac and ping from my Debian and they answered Ok. I also have access to internet from Debian, because I have the same Default Gateway as my Mac.
root#debian64:/home/myuser# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default TEW-711BR 0.0.0.0 UG 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
I hope it helps and if anybody have better explanations I would like to learn.
For study purpose I want to setup the following networking
A:
10.130.247.92/16(private on eth1)
128.199.227.240(public on eth0)
B:
10.130.237.218/16(private on eth1)
128.199.211.182/18(public on eth0)
And use B as gateway for private route.
in A
root#privte2:~# ip route list
default via 128.199.192.1 dev eth0
10.130.0.0/16 dev eth1 scope link
128.199.192.0/18 dev eth0 scope link
and
root#privte2:~# ip route add 10.130.0.0/16 via 10.130.247.92 dev eth1
RTNETLINK answers: File exists
Can anyone tell me where i did wrong?
I tried something like this before. See if this can help you. First enable the ipforwarding in both the machines.
locate the line containing net.ipv4.ip_forward in the /etc/syscl.conf file and make the following change.
net.ipv4.ip_forward=1
May be you need to restart for this.
Not really sure, Try this route command and see if it works.
Machine>$ route add -net 10.130.0.0 netmask 255.255.255.0 gw 128.199.211.182
For instance see here.
I have successfully setup a Raspberry PI VM on my Mac OS X via QEMU. Now I want to access the filesystem of this VM from my Mac.
When I call ifconfig on my VM I get this.
And here the content of my /etc/network/interfaces file
On my Mac
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
ether 3c:07:54:65:da:50
inet6 fe80::3e07:54ff:fe65:da50%en0 prefixlen 64 scopeid 0x4
inet6 fdbf:a879:6730::3e07:54ff:fe65:da50 prefixlen 64 autoconf
inet6 fdbf:a879:6730::401e:56f5:f2f9:a236 prefixlen 64 autoconf temporary
inet 192.168.1.119 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=1<PERFORMNUD>
media: autoselect (1000baseT <full-duplex,flow-control>)
status: active
I think the reason is, that the VM uses some kind of Shared Network. Is there a way that the VM get the IP address from my router?
The easier method - less flexible but you don't need to muck around so much
They way you have configured qemu appears to be the default host NAT network (aka. qemu -net nic -net user configuration)
By default, your host (your Mac in this case) will be found on 10.0.2.2 when accessed from your guest. From inside your guest you can connect to services on your host (your MAC) at 10.0.2.2. But this is using NAT, so you can't go back the other way as easily.
For example, if you decide to you want to connect to the SSH service and a web server running inside your guest, you will need to start qemu with modified options like the following:
qemu -net nic -net user,hostfwd=tcp::2222-:22,hostfwd=tcp::22280-:80
What this will do is route connections from port 22280 on your host (your MAC) to port 80 inside your qemu guest, (same for port 2222 --> port 22 in the guest)
Which means you can browse to http://localhost:22280 on your Mac, to get to the web server in your virtual Raspberry Pi, etc.
FTP and SMB will be more complicated to setup this way because of the different ports used and they way they are used, etc. although if you setup FTP to use PASV mode it wont be too much of a problem.
The more complicated method
This involves doing what you suggested, configuring the virtual machine quest to be able to get an IP address from your router. In this case, you need to make a bridge from your virtual machine onto your hosts network.
This requires a lot more setup than can be quickly explained here, but essentially, you need to assign your NIC to a vlan and add a tap interface, for example:
qemu -net nic,vlan=0 -net tap,ifname=tap0
This however requires more setup on the host (initially, manual, as you figure out your own situation, but then, scriptable) to create a bridge and tap interface - which usually requires root access beyond that needed to simply run qemu. A bit of Googling brings up a variety of methods to do this, because it varies more depending on your setup. (I found an example setup script here: https://gist.github.com/EmbeddedAndroid/6572715 )
Note - network MAC addresses, network card models, etc. and other qemu options omitted for clarity.
The SAMBA method
Note: I have only tried this under Linux
You can enable a samba server inside qemu:
qemu -smb /path/to/files
This creates a SMB share accessible from inside the guest at \10.0.2.4\qemu mapped from /path/to/files on the host.
If you are happy to use SFTP/SCP then IMO the easiest thing to do is to install openssh-server on your Pi guest:
sudo apt-get update && sudo apt-get install openssh-server
When you launch your Pi VM use the -redir switch when your launch your QEMU guest to redirect port 22 (SSH/SFTP/SCP) e.g.
qemu <other-qemu-switches-options-etc> -redir tcp:2222::22
You can then connect to your VM SFTP/SCP (or SSH) via port 2222 on your host machine. So from your host you can use localhost; from other machines on your LAN you can use :2222
[update 2019] As noted by #ChristophBimminger in a comment, in newer versions of QEMU the -redir switch has been deprecated/removed. The way to achieve this same thing is now via the -net or -netdev switches. Please check the man page, e.g. Debian testing (I don't currently have a QEMU running so can't give a definitive example).
In either http.request or net.connect, is there an option that I can specify a network interface to initiate a connection?
EDIT: AFAIK in OS level I can specify address level, or load balancing into routing tables. But the way of interface choosing in my software is more than that, I wanna know if I can do that in codes.
Node has this built in:
http://nodejs.org/api/net.html#net_net_connect_options_connectionlistener
http://nodejs.org/api/http.html#http_http_request_options_callback
See localAddress, just set that to the IP of the interface you'd like to use.
EDIT: As mak pointed out, it is indeed possible to specify a network interface from a user process. I stand corrected. However, I haven't yet found a module that allows it with node.
By default, the network interface is determined by the OS routing table.
You can list this table with netstat -r on Unix systems (OSX included). Just open a terminal and type the command. You will get a listing like:
laurent ~ $ netstat -r
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.1.1 UGSc 153 0 en0
127 localhost UCS 0 0 lo0
localhost localhost UH 2 42 lo0
...
The Netif field gives you the network interface used for the route. You can also get the interface used to reach a hostname with route:
laurent ~ $ route get google.fr
route to: par03s02-in-f23.1e100.net
destination: default
mask: default
gateway: 192.168.1.1
interface: en0
flags: <UP,GATEWAY,DONE,STATIC,PRCLONING>
recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
0 0 0 0 0 0 1500 0
This is more a serverfault thing, but you can change routes with the route command. For example, this will route traffic to X.Y.Z.[0-254] to X.Y.Z.254 on eth0:
route add -net X.Y.Z.0/24 gw X.Y.Z.254 dev eth0
If you want routes to persist a reboot, you can add them to /etc/network/interfaces. If you want to load balance between several different routes, you should also check MPLS.
You can use node cURL wrapper
curl = require('node-curl')
curl('www.google.com', { INTERFACE: 'eth1', RAW: 1 }, function(err) {
console.info(this);
});