简体   繁体   中英

Node.js outbound IP - change address

OS is Linux Debian 9. My network interface has few IPv4 attached to it and can have some IPv6 as well.

Network interface setup file adds at the end one of /64 group IPv6 address.

How to run node.js to use one choosen IPv4 as outbound connection from list of IPv4 addresses? Now it uses always interface's the last added IP.

I wouldn't like to setup proxy on these IP's cause they are used at webserver and other services.

I've prepared some code which shows a little what the problem is:

var ip = require('ip');
console.log(ip.address());

const puppeteer = require('puppeteer');

(async() => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://api.myip.com/');
  let bodyHTML = await page.evaluate(() => document.body.innerHTML);
  console.log(bodyHTML);
  await browser.close();
})();

So as you can see, I've listed here my local IP address and in advance I have opened website https://api.myip.com/ with puppeteer (thanks @crazyluki) to show its outbound IP in json.

So results are:

seo@serv:~/goo$ node ip.js 
188.6.6.1
{"ip":"1001:a1d0:2:9aa1::","country":"France","cc":"FR"}
user@serv:~/goo$ 

added new IPv6:

user@serv:~/goo$ sudo /sbin/ifconfig eno1 inet6 add 1001:a1d0:2:9aa1::1/64

and then:

user@serv:~/goo$ node ip.js 
188.6.6.1
{"ip":"1001:a1d0:2:9aa1::1","country":"France","cc":"FR"}
user@serv:~/goo$ 

So as we can see IP address changed from 1001:a1d0:2:9aa1:: to 1001:a1d0:2:9aa1::1

How to make control on outbound IP in puppeteer not using proxy for my local IPv4 addresses?

If I visit https://api.myip.com/ with Lynx it also shows IP like puppeteer.

Okay guys, I've configured squid. Seems there is no other way to achieve desired result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM