Is there any way to dump IP route so that I can save this dump in database and then execute the routing commands one by one without having any error. (I am not network guy but working on an application which interacts with the network)
Please note that currently I am using 'ip route list' but getting errors as these commands are not in proper order. Some of the gateways must be reachable first before routing other IP address from these gateways.
with a router, you can use the show ip route static to display the static route, for dynamic route, it has no meaning dump because they are all generate by the router.
Related
I am using the ip library of npm.
I have two config files, one for React and one for Node, for the same application.
const ip = require('ip');
console.log(ip.address());
This returns different ip addresses for the React config file(inside the src folder-127.0.0.1) and Node server file(outside the src folder - IPv4 address).
The issue is that I am pretty sure that I ran the exact same code earlier and it gave me the same ip addresses for both as then I was able to access my webpages. I need the same ip to make requests to my node backend, I cannot afford it in production. Are there other definite methods of doing this?
You get different ip results because 2 method call ip.address() are using different network interfaces.
To make ip.address() return identical result, you can pass network interface name as the first parameter, such as en0:
const ip = require('ip');
console.log(ip.address('en0'));
p.s. To get all current networks interface names, os.networkInterfaces() can be used.
Update: OP try to get IP address in React code, in browser side. This is mission impossible. Otherwise, it would bring huge security problem.
Update 2: OP don't want to store endpoint IP address in frontend code for security reason, neither want to retrieve the IP address first (network overhead issue). In this case, you can make a proxy in server. All frontend know is interacting with current server, the data exchange is delivered by server as:
Browser <--> Server <--> Various endpoint IP
The steps are:
The server (that host the frontend code) get request from browser
Server check which endpoint would be used for that client
Server send the request to specific endpoint
Server get response from endpoint
Server return the response in above step to browser
I have build a node js code for an API server. Part of one feature is that when it starts, it should be able to know its own IP, despite the type of setup of the server where it is running.
The classic scenario is not that hard (I think). There are several options, like using the os module and find the ip or the external interface. I am sure there are other ways and some might be better, but this is the way I have been doing it so far. Feel free to add alternatives as informative as possible.
There is this case that I stumbled on. In one case, the web server was running on a google cloud instance. This instance has two IPs, one internal and one external. What I want is the external IP. However, when I use the method above, the actual external IP is not part of the object returned. The internal IP is declared as being considered as non-internal. Even when I run different commands from within the server command line, the only IP returned is the one that is actually internal and cannot be used to access the node server.
From what I understand, the instance itself is not aware of it's external IP. There might be a dns (I think) that redirects requests made to the external IP towards the correct instance.
While reading in the internet I read that problems getting the server's correct external IP might also rise when using load balancing or proxies.
The solution I thought about is to have the node js code make a request towards a service that I will build. This service will treat the node js servers as clients, and will return their external IPs. From experiments that I have done, the req object contains among others the information of the client's IP. So I should check first req.connection.remoteAddress and then the first element of req.headers['x-forwarded-for']. Ideally the server would make a request towards itself, but
I know there are external API like https://api.ipify.org?format=json that do just that - return the actual IP. But I would very much like to have the node js servers independent of services I cannot control.
However, I really am hoping that there are better solutions out there than making a request from the server which returns the server IP.
However, I really am hoping that there are better solutions out there
than making a request from the server which returns the server IP.
It is not really possible, you always rely on some kind of external observer / external request.
While reading in the internet I read that problems getting the
server's correct external IP might also rise when using load balancing
or proxies.
This is because not in all scenarios your own device is able to be self-aware of its external ip. There might be sitting behind some network, that means external address assigned to devices that forwards the WAN to it. (example : router) so when you try to obtain external ip from the devices interface itself, you end up obtaining an ip but inside the scope of the routers LAN and not the one used for external requests .
So if you really want to
Have a method to use in all scenarios
Not rely on 3rd party services
Only Solution :
Build your own ip echo service (you maintain and can use for future projects).
So I am currently working on a destination based routing setup, and I'm really new to the world of Linux. I'm mainly trying to get this to work for video, so what I want to do is route any traffic that I specify through my vpn, and keep the rest of the traffic local. I tried to do this with BBC iPlayer, and I ended up reaching a roadblock because nslookup did not yield the server addresses for Akamai, BBC's CDN. I used tcptrack to find all the incoming connections onto my machine, and I sorted it by connection rate, and the top few would end up being the akamai servers. Well, once I figured this out, I am currently trying to automate the process, and I cannot get tcptrack to write to an output file. Does anyone know of a way to get tcptrack to write to a text file or know of a program that would be better suited to my purpose? What I currently do is use the route command and route the server address, both the one that tcptrack gets me and the nslookup address, through to my vpn using the syntax route add (server address) dev tun0. Any help would be appreciated!
Not sure if i understand the context correctly but if you want to direct specific traffic say based on client IP or domain name then this is possible using Akamai.
I'm using Node.js and Express as backend to my app, and wish to upload a photo to facebook.
I came across this method of uploading an image by url: https://developers.facebook.com/blog/post/526/
Now all I need to figure out is what is my own base url, so I can assemble the full address of mt photo (say /photos/12345 should be http://www.mydomain.com/photos/12345)
Is there any way to do so? some Node env variable perhaps?
Thank
Basically, you bind Node.js / Express to a port, and perhaps to an IP address. So your question comes down to:
Is it possible to find out just by an IP address which domain name it is used by?
And the answer to that is simply: No, unfortunately not.
Reason: You can bind several domain names to the same IP address. So all you could do is query the DNS server of your choice for a reverse-lookup of the IP address to get a list of domain names. If you are lucky, there is only one. If not, there are more.
And, as an additional problem: If your code does not explicitly bind itself to a specific IP address you do not even know which IP address to use - there will be more than one: At least a IPv4 one, loopback, probably IPv6, ... potentially more if there is more than one network card, ...
So, bottom line: If you have a lot of good luck, yes, but there is no reliable method that works under every circumstance.
I have a gateway server that is also acting as a web proxy for clients and I need to get some information about the network connections. The gateway server has an internal and an external interface/IP-address.
If I use the 'netstat' or 'ss' command I get a display showing of all the clients' internal IP addresses/ports connecting to the gateway's internal IP address/squid-port. But if I run 'iftop' I get a display of the clients' internal IP addresses and the external IP address/port they are ultimately connecting to, it seems to ignore the proxy middleman.
The information from iftop is what I need, that is, internal ip:port to final ip:port ignoring the proxy, but I need to parse the output and can't seem to do that with iftop as it is interactive. Does anyone know a way to get iftop like information from a standard Linux command?
Thanks
If you are using a typical HTTP proxy setup, ss -at will show two entries: one for client--proxy, and one for proxy--webpage, just as it should, because two connections are live in such a case.