Skip to content

http.get option localAddress not working #3625

@k1tzu

Description

@k1tzu

Hello! The binding to Local interface option is not working at all.
The case: Arch Linux system with two different ethernet interfaces.
eth0: 192.168.0.173/24
eth1: 192.168.0.182/24
routing table is
default via 192.168.0.1 dev eth0 metric 280
default via 192.168.0.1 dev eth1 metric 281

Every interface has a listening http server on other end with the address: 192.168.0.1
So I'm trying to send a request to each of them with nodejs.
Sample code:

var http = require('http');
var options = {};
options.port = 80;
options.host = "192.168.0.1";
options.path = '/index.html';
options.headers = {'Referer': 'http://' + options.host + ':' + options.port + '/index.html'};

options.localAddress = '192.168.0.182'; //NOT WORKING!! - REQUEST GOING FROM 192.168.0.173!

var creq = http.get(options);
creq.on('response', function (res) {
    res.on('data', function (chunk) {
        console.log(chunk);
    });
});

I've even tried creating a socket for that request with new net.Socket({ handle: net._createServerHandle( '192.168.0.182')}); and requests kept going from the wrong address.
There's workaround with 'curl --interface eth1 ...' that works, but it's not a good solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.httpIssues or PRs related to the http subsystem.questionIssues that look for answers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions