Same server, same program but started once using one network card and after with another - linux

I have a Linux server with multiple ips (so, multiple eth0, eth0:0, eth0:1 etc).
The script I'm trying to start is a php CLI script which is downloading stuff from an another server API, and I would like to change the IP based on different parameters. Once the script is started, I don't need anymore to change the ip OF THAT SPECIFIC script until his end.
Do you have any clue if it is possible to achieve it?
My other solution was to install Xen or OpenVZ and create N different VPS per each IP, but as you can see is definitely a PITA :-)

You don't specify how you connect to the other server, but with sockets you can try socket_bind.
EDIT:
With curl you can try curl_setopt.
CURLOPT_INTERFACE The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.

I know how to do it in C - you use bind() on your socket before you call connect(), and you bind to the IP address assigned to the desired interface, passing 0 for port. I don't know how to do it in PHP.

Related

how to create ip alias in nodejs

I am writing test in nodejs.
Calling my api using requestjs.
Now I have to make one call using an ip address to the api (/resources/media)
Then I have to make another call to the same api (/resources/media) using different ip from the same computer.
OS: ubuntu
any idea how to do that
help is very much appreciated.
Thanks
Your only choice is to set up a proxy (like squid), bind it to another (virtual) networking interface card and make the second request through it.
add another ip and make sure it was not existed before
sudo ip addr add 192.168.50.5 dev eth1
Then user localAddress option in requestjs

Finding server in LAN

How to find, in python, server without having it's IP in LAN?
I assume that port will be configured in file so its doesn't have to find port. I tried to search on google but I couldn't find anything useful or that could help me with it.
The server IP will be changing because it will not run constantly on the same computer.
So basically I got app with server that is on random computer in network, and I want to find its IP from another computer.
I would be really thankful for either explanation how to do it or link that could help me to do it.
Not certain if this is what you want to do, I think you want to find the IP of a server by running some python execution on the server?
You could try :
from subprocess import call
call (["ipconfig"])
This will dump the IP config and you can parse out the IP address. This assumes a windows server. You would have to modify the call for your OS.
Updated :
Check this out : TCP Communications or UDP Communications ... it looks like what you are looking for. You will still have the mess of determining the available addresses on the network (arp -a), and testing each one - this would be your client side app. Your server side app, when it receives the right query on the TCP or UDP port, would then determine it's address (ipconfig) and return the value.

How to forward incoming clients based on ip to a specific process

I have a server that has multiple ip addresses. It also has multiple web apps written in nodejs that I'm running.
In short I'd like to forward specific ip addresses to specific node applications. How is this done? Should I use apache or nginx?
running centos 7
Any running application can bind to either 0.0.0.0 (to catch all the packets) or to some specific IP (it must use this ip when it calls bind() on the socket). Thus almost any TCP/IP server application has option like "Listen" in it's config file or command line, so you should read your docs carefully to figure out how can it be made in your particular application. For Apache it's port-based virtual hosts.
If you want to route user requests to different application based on user's IP address, you should read about iptables nat table and REDIRECT target.

Is there a way to use DNSMasq and BIND on the same computer?

I like the idea of running my own nameserver (BIND) but if I do that, I can't get the benefit of blocking nasty websites by putting them in /etc/hosts
DNSMasq is able to refer to /etc/hosts but rather than specifying an "upstream" dnsserver, I'd like it to be able to use BIND on the same machine. However, they both need to use the same port.
Is this possible? I couldn't find anything about this in regular searching.
I suppose an alternative would be to run another Linux instance in a VM and run DNSMasq there (say) but I'd like to not have to do this.
you could assign multiple ip addresses to the same interface, either with
ip addr add <address>/32 dev eth0
or using
ifconfig eth0:1 <address>
then bind one server to one address, the other server to the second address.
Which server is queried depends now on the ip address your queries are sent to.
The examples assume that your eth interface is eth0.

xampp server (How to get up and running)

I've been developing locally on a little ubuntu netbook with xampp for about 7 months. Two weeks ago I got a computer I'd like to use as a server. I've installed the latest Ubuntu distribution and xampp, moved all my files over, and forwarded port 80. I've also got a domain name from dyndns.com which is being updated by a client which runs in my router (a Netgear WGR6154 v8).
Now, when I try to access my server by typing in the address I got from dyndns.com the browser loads until it timesout. I can access everything locally using localhost as the address so I believe xampp is running, just unable to connect with the internet.
In order to be able to view my files over the internet what should I do next?
Thanks to all in advance...
[I'm starting a bounty for the first person to help me get my files successfully online]
You have a combination of issues here, and that is something of a problem. Each issue is complex in an of itself. Here is what I would recommend to get you going for certain.
First verify that you can surf the web from your server. This will confirm that you have a working ethernet interface.
Step 1 make sure that XAMPP, and your files are viewable from your home network. I assume you are using something like 192.168.1.X for your network and perhaps your server is 192.168.1.10
Go to another computer in your house and type http://192.168.1.10/ and see if you can see your files. If you can then you know that the server is properly configured and XAMPP is working.
Then add an entry to your hosts file to resolve yourdnsrecord.com (or whatever your dyndns record is) to your private ip address. Then when you type yourdnsrecord.com into a browser from that computer you should still get your files. This will rule out your server being improperly configured to listen for that domain name.
Next you need to test to see if there is a firewall problem. To simplify this, first remove your home router from the equation. Instead, place your new server directly onto your internet connection. (assuming you can). This way, you do not need to have NAT or firewalls properly configured. Your dyndns name should map to a public IP and your server should then have that IP and be connected directly to the Internet. If you have your server directly connected, and the command ifconfig from the root prompt returns the same public IP address that your dynamic dns record is point to, then it should work.
It will make your life easier if you have an iphone or some other way to test how your network is seen from the Internet.
If your public IP as shown by ifconfig is different than the IP record in your dyndns account, then your dynamic dns update script is broken. manually set the IP, and see if things work.
It is very possible that this will not work. Some ISPs firewall port 80 preventing their subscribers from hosting servers. Once you have your server directly connected to the internet you can test this (even if your dns is not working) by using the public IP address. As root, type ifconfig from the command prompt to get your public ip address. Then type the command tcpdump -i eth? port 80 from the root prompt. eth? needs to be the same interface that you saw had a public IP address from the ifconfig command. usually this is eth0 but it might be wire0 or something like that.
This command will show you all traffic coming on port 80 to your server.
From an iphone (or whatever second Internet connection you have) browse to the IP address that you got from your ifconfig command. If you see something on your server (and it is directly connected to your ISP) then your ISP is not firewalling you.
If you can get to your server, when it is directly connected to the Internet, either by IP address or by DynDNS address, then your ISP is OK and it is time to debug your firewall.
Two things need to work for your firewall to be configured NAT, where the public address that your router gets from your ISP is converted into your private network and a firewall rule which permits that traffic. If you get this far, then you know your firewall is the problem and then it is just a matter of getting its configuration correct. There are far to many home routers to document here, but you usually can find how-to instructions for your router for this task from the manufacturers website (usually it is part of the manual)
If you follow these instructions exactly you will get your system working. Make comments on the process and I will be happy to modify this to make it clearer.
HTH,
-FT
You should make sure your xampp is not listening to only the localhost.
to do so edit your apache configuration file and check and search for Listen directive
you should be able to know also by analysing the output of netstat -a.
After that make sure your router is forwarding properly, using tcpdump would help.
drop me a comment if you need more help.
Cheers

Resources