OpenSIPs stun module require two IP addresses - linux

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.

Related

Two wired connection at the same time

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.

Send traffic to self over physical network on Ubuntu

I have a dual port ethernet NIC and let's say I have connected 2 ports in a loop and assigned the following IPs to the 2 ethernet interfaces:
eth2 -> 192.168.2.1
eth3 -> 192.168.3.1
I want to send traffic from 1 port to another over the physical network, e.g. ping 192.168.3.1 from 192.168.2.1. However, the TCP/IP stack in the Linux kernel recognizes that these two addresses are local and instead sends the traffic to the loopback adapter, so the traffic never hits the physical network.
The closest I have to a solution is Anastasov's send-to-self patch, which unfortunately, has been discontinued since kernel 3.6 so it won't work on Ubuntu 13.10 (kernel 3.11) for me. I've tried finding rewriting the patch for 3.11, but I can't seem to locate these in the Ubuntu distro:
include/linux/inetdevice.h
net/ipv4/devinet.c
net/ipv4/fib_frontend.c
net/ipv4/route.c
Documentation/networking/ip-sysctl.txt
Is there a way I can get the send-to-self patch to work, or an alternative?
You can use network namespaces for this purpose.
As ip-netns's manpage says:
A network namespace is logically another copy of the network stack,
with its own routes, firewall rules, and network devices.
Following is just a copy of this answer:
Create a network namespace and move one of interfaces into it:
ip netns add test
ip link set eth1 netns test
Start a shell in the new namespace:
ip netns exec test bash
Then proceed as if you had two machines. When finished exit the shell and delete the namespace:
ip netns del test
you can try configuring route table, by running "ip" command:
ip route add to unicast 192.168.3.1 dev eth2
ip route add to unicast 192.168.2.1 dev eth3
new route would be added into route table, and it should be able to take effect before egress routing lookup hit the host-local route between "192.168.3.1" and "192.168.2.1", therefore, the traffic should be sent through physical interface "eth2" and "eth3", instead of loopback "lo"
Never tried myself, but should work.

Which interface linux will use between eth0 and eth0.1?

I have a VPS on which eth0 is configured , i want to configure a interface eth0.1 but i want to know if i will configure this new interface the data flow will be divided between eth0 and eth0.1 ?
I want to use eth0 Ip address for all the data flow on server like custom written scripts and eth0.1 Ip address to access it from browser as i have web-server on it.
Linux, by default, will send all packets out the default interface for the subnet, which is most likely eth0.
iproute2 attempts to solve this problem by redirecting packets out on the same interface on which they have been received.
http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2
So, to answer your question, most packets on your system will probably already go out eth0 (assuming it's the same subnet).
If you set up an alias interface, eth0.1 (from your example), any programs listening on either all interfaces, or specifically, to eth0.1 will be able to receive packets on that IP address.
To add a secondary IP address you use the : separator on the interface name. Suppose you have eth0 assigned with 11.22.33.44 and you also want it to work with 11.22.33.55. Then you would just do:
ifconfig eth0:1 11.22.33.55
If you don't touch routing through the ip route command, 11.22.33.55 won't ever be used as an outbound interface, unless you're answering a request that points to 11.22.33.55 itself, so there are two more things to do.
The first is setting up your webserver's listening address to 11.22.33.55 instead of 'any' IP or 11.22.33.44. This depends on your webserver, in the case of apache check out the Listen directive.
The second thing, if you use a domain, to do is setting up a DNS record to point to 11.22.33.55 instead of 11.22.33.44. Take care because a domain name can't be resolved to a different address depending on the destination port, so you'll need a domain name for each interface. The alternative is directly using the IP address 11.22.33.44 for the script stuff and using the domain name for the webserver only.
After you've done this you can safely use tcpdump, iptables & friends on both the physical and the virtual interface.

Adding Linux machine in specific vlan

We have one linux machine (Fedora).In our network we have multiple vlan's (Say VLAN-A, VLAN-B, VLAN-C). By default through dhcp out machine is getting ip from VLAN - A.
Now for some testing We need to configure ip of VLAN-C. But when we are assigning static IP of VLAN-C in machine, it not able to ping/connect other machines of VLAN-C
Is there any way in linux client to assign IP of VLAN-C.
The vconfig program allows you to create and remove vlan-devices on a vlan enabled kernel. Vlan-devices are virtual ethernet devices which represents the virtual lans on the physical lan.Please note that this is yet another method of configuring VLAN. If you are happy with above method no need to read below.
Add VLAN ID 5 with follwing command for eth0:
vconfig add eth0 5
The vconfig add command creates a vlan-device on eth0 which result into eth0.5 interface. You can use normal ifconfig command to see device information:
ifconfig eth0.5
Use ifconfig to assign IP address to vlan interfere :
ifconfig eth0.5 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 up
Get detailed information about VLAN interface:
cat /proc/net/vlan/eth0.5
If you wish to delete VLAN interface delete command:
ifconfig eth0.5 down
vconfig rem eth0.5

Change IP address via shellscript on Slackware

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

Resources