I'm trying to create a bash script and a small part of it requires figuring out if, given an IP address of another computer, what interface is on that same network.
So if my computer is has the following interfaces (not including lo):
eth0 Link encap:Ethernet HWaddr XX
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
wlan0 Link encap:Ethernet HWaddr XX
inet addr:192.168.5.100 Bcast:192.168.5.255 Mask:255.255.255.0
and I know that there is a computer at the following address:
192.168.0.101
is there a simple way to extract the answer eth0?
P.S. This question is NOT asking about getting the the interface given the address of my own computer like this post is.
no, the name eth0 is not broadcasted in any way, so there is no way to get it remotely. it is just a name that is only internally used.
You'd have to log into the remote machine (ssh) and get the info using for example ifconfig.
if you need the macaddress of the remote machine (on your network) use arp:
arp 192.168.0.101
Related
I have run into issue with running JVM processes on Docker after upgrading library due to development reasons to new version (Corda 4), as up to now I was setting the program (node) running in a Docker container to listen on all interfaces (0.0.0.0) while running in host mode on AWS EC2, which would bind it to all network interfaces, listening on all interfaces and using that forward.
Now in latest, 4, they have coded in https://github.com/corda/corda/blob/061db8b1a1ac1fa9f1a063caf7ce4f009aa283db/node/src/main/kotlin/net/corda/node/internal/Node.kt#L322 preventing this feature.
This in conjunction with https://docs.corda.net/corda-configuration-file.html
In practice the ArtemisMQ messaging services bind to all local addresses on the specified port. However, note that the host is the included as the advertised entry in the network map. As a result the value listed here must be externally accessible when running nodes across a cluster of machines. If the provided host is unreachable, the node will try to auto-discover its public one.
This results in having to specify the public IP in the node configuration, which it then tries to bind to, but it cannot as EC2 does not have the public ip visible as a direct network interface, just an internal routing interface(NIC) which at a later stage in their stack gets translated to public IP.
AWS EC2 instance ifconfig:
br-9121696521bd Link encap:Ethernet HWaddr 02:42:56:7C:6A:27
inet addr:172.18.0.1 Bcast:172.18.255.255 Mask:255.255.0.0
...
docker0 Link encap:Ethernet HWaddr 02:42:78:C3:69:1B
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
...
eth0 Link encap:Ethernet HWaddr 02:5F:BE:63:67:82
inet addr:10.0.0.56 Bcast:10.0.0.255 Mask:255.255.255.0
...
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
...
veth0c214d6 Link encap:Ethernet HWaddr BE:2A:29:08:94:B3
inet6 addr: fe80::bc2a:29ff:fe08:94b3/64 Scope:Link
...
veth2b54799 Link encap:Ethernet HWaddr 66:81:E9:01:91:10
inet6 addr: fe80::6481:e9ff:fe01:9110/64 Scope:Link
...
veth60fffa5 Link encap:Ethernet HWaddr 7A:FE:10:33:A9:80
inet6 addr: fe80::78fe:10ff:fe33:a980/64 Scope:Link
...
vethe4f9a9a Link encap:Ethernet HWaddr EE:C7:CB:C8:25:85
inet6 addr: fe80::ecc7:cbff:fec8:2585/64 Scope:Link
Outcome:
Corda now forces me to set in node.conf p2pAddress which is then published to NMS, and used by other nodes to communicate with it.
I cannot set EC2 public IP as Corda attempts to "bind" to the NIC with that hostname, which is not exposed directly to EC2
I cannot set it to 0.0.0.0 to make it bind to all nics and listen to all incoming routes as they hardcoded in core Node.kt to stop node if 0.0.0.0 provided
I can only set to ip visible in container/host which are not visible outside -> node unreachable
I have looked at trying to fool Docker network stack into representing its local ip to that of the external ip as it is virtual network layer, but it only provides subnetting ability to existing NIC (10.0.x.x IP) or in loopback ip ranges ( 192.168.x.x or 10.x.x or 172.x.x.x)
This post Running corda nodes in different machines also exemplifies precisely my issue and the solution i came to as well, which they closed off in 4.0
Question/Possibilities
Option 1 (AWS/Docker):
Spoof Public IP to be visible in EC2 as actual NIC IP via Docker IPAM/Pipeworks or Linux specific via IP masquerading with a virtual interface ?
Option 2(Corda specific):
Change configuration to somehow accept 0.0.0.0 or make detectPublicIp be more inteligent and use NMS to discover its own IP. I expected it to have this intelligence but I later discovered it just looks on at available NIC's. It fails with AMQ224000 error.
From my understanding Corda 4.0 is unable to run on public cloud providers (Azure/AWS/GC) due to it requiring NIC with Public IP to be present, element which Azure/AWS/GC do not have available, could somebody from Corda team correct me if I am wrong ?
If I understand correctly, the internal Artemis server cannot bind as it's using(by default) the p2pAddress which now has to be a valid public one. You can override this by providing a messagingServerAddress as well. See https://docs.corda.net/corda-configuration-file.html?highlight=messagingserveraddress for a bit more details.
I am struggling with a network problem.
My computer needs to be linked to two differents networks. one via PCI the other one via a USB adapter. The pci is the "usual" network, the usb is to use for specific address.
I have tried differents solutions, with dns, multiple wired connection, modifiying /etc/network/interfaces, ...
But I can't manage to have the 2 networking working at the same time.
Do you have any solution. I am working with Debian - jessie.
Cheers
Since you haven't specified any networks, IP addresses or device names, I will use my machine as an example.
I have an IOGear ethernet USB dongle which shows up as device enx0050b6d341bb, and an RTL811 PCI ethernet device which shows up as eth0. eth0 is plugged into the "main" network which has a DHCP server and enx0050b6d341bb is connected to a private switch on my workbench.
If I want to use eth0 to connect to the internet, but use enx0050b6d341bb to connect to anything on network 192.168.168.0/24, /etc/network/interfaces will look like this:
auto lo
iface lo inet loopback
# Obtain DHCP address from server
auto eth0
iface eth0 inet dhcp
# Connect to 192.168.168.0 network
auto enx0050b6d341bb
iface enx0050b6d341bb inet static
address 192.168.168.3
network 192.168.168.0
netmask 255.255.255.0
Since I only have one device using DHCP, my default route will automatically go through that device, which happens to be exactly what I want :-)
solargy#GEPY633007AX:~$ ip route
default via 192.168.10.1 dev eth0
192.168.10.0/24 dev eth0 proto kernel scope link src 192.168.10.67
192.168.168.0/24 dev enx0050b6d341bb proto kernel scope link src 192.168.168.3
The above shows that my default traffic will go through eth0 and that any traffic for addresses in network 192.168.168.0/24 will go through enx0050b6d341bb. To verify that, you can find out which device will be used to communicate with address 192.168.168.2:
solargy#GEPY633007AX:~$ ip route get 192.168.168.2
192.168.168.2 dev enx0050b6d341bb src 192.168.168.3
cache
As you can see, any traffic for 192.168.168.2 will go through enx0050b6d341bb.
I have to make a STUN server in OpenSIPs, and it says that I need to bind 2 IP addresses.
http://www.opensips.org/About/News0042
A STUN server uses 2 ips and 2 ports to create 4 sockets on which to listen or respond.
STUN requires 2 routable ip addresses
How can I enable two public IP addresses into one Linux server? I've searched all website, and failed to find the answer.
Several options.
Option 1.
You likely just need to use ifconfig from the command line to start
You can assign an additional static IP address to your NIC via the command line. Type ifconfig to get the name of your default adapter. It's typically "eth0". Then do add a secondary address to this adapter, the command is something like the following:
sudo ifconfig eth0:1 inet up netmask 255.255.255.0 192.168.1.55
Where 255.255.255.0 is the netmask of my 8-bit subnet and 192.16.1.55 is an existing IP address that no other device on my subnet is already using.
Option 2.
After you get your server up and running with Option 1, you likely need to find a way to get the IP address assigned by "ifconfig" to persist after a reboot. You could likely stick an ifconfig statement into one of your rc.init files. But most Linux skus have a formal way of configuring an interface with another /etc file. But this step varies between different flavors of Linux. On Ubuntu, this is all defined in the /etc/network/interfaces file. Add these three lines to the bottom of your existing file:
iface eth0:1 inet static
address 192.168.1.55
netmask 255.255.255.0
Option 3 (shameless plug)
Switch to Stuntman ( www.stunprotocol.org ) as your STUN server. Its default mode only requires one IP address to be present on the box. Most client usages of the STUN protocol don't require the second IP address unless to do NAT classification and behavior tests.
I have a problem:
When I try to connect to a network, initially with ifconfig eth2 I get (correctly):
eth2 inet addr:192.168.1.56 ....
inet6 addr: fe80:221:ff:fe96:4598/64
but after a few seconds the 102.168.1.56 disappears and after some other seconds disappears the inet6 address too. In this case the network is wireless and no DHCP.
At uni, the connection is a DHCP one. It works for the first few seconds but after it doesn't.
Any possible solution?
Whats this 102.168.1.56?
cat /var/log/syslog will give more info about what happening in the system. Usually it contains large amount of information.
In a shellscript, I'd like to set the IP of my box, run a command, then move to the next IP. The IPs are an entire C block.
The question is how do I set the IP of the box without editing a file? What command sets the IP on Slackware?
Thanks
As mentioned in other answers, you can use either the ifconfig command or the ip command. ip is a much more robust command, and I prefer to use it. A full script which loops through a full class C subnet adding the IP, doing stuff, then removing it follows. Note that it doesn't use .0 or .255, which are the network and broadcast addresses of the subnet. Also, when using the ip command to add or remove an address, it's good to include the mask width, as well (the /24 at the end of the address).
#!/bin/bash
SUBNET=192.168.135.
ETH=eth0
for i in {1..254}
do
ip addr add ${SUBNET}${i}/24 dev ${ETH}
# do whatever you want here
ip addr del ${SUBNET}${i}/24 dev ${ETH}
done
It should be something like: ifconfig eth0 192.168.0.42 up
Replace eth0 by the network interface of your network card, obviously adapt the ip address to your needs and the up is only necessary once, but doesn't hurt if you run it each time.
I don't know Slackware very well, I last used it over ten years ago. However, any mainstream Linux distribution should have either the 'ifconfig' program, or the 'ip' program or both. You will need to have root privilges, so either become root (e.g with su) or use the 'sudo' program if you know how. Let's do it with 'ip' first.
ip addr add 10.1.2.3 dev eth0
sets the device eth0 (usually the primary wired network adaptor) to have IP address 10.1.2.3. You can remove the address from this adaptor again when you're done with it...
ip addr del 10.1.2.3 dev eth0
ifconfig works a bit differently,
ifconfig eth0 10.1.2.3 netmask 255.255.255.0
again sets up device eth0, with IP address 10.1.2.3
Depending on what you want these addresses for, you may also need to know how to set up a manual route, so that your IP packets actually get delivered wherever they're going.
In one line, e.g.: ifconfig eth0 192.168.10.12 netmask 255.255.255.0