Sam Berg
Sam Berg

Reputation: 189

How can I find the host machine network ip address on travis?

Sorry for the naive question but I am new to using travis and read the docs thoroughly but I can't figure out what exactly I need to put in my .travis.yml or use as an IP address.

I have setup my server on local host in travis. For client testing I need the ip address of the local host to test my client app.

Any help is highly appreciated. Thanks :)

Upvotes: 3

Views: 890

Answers (1)

sideshowbarker
sideshowbarker

Reputation: 87984

This works:

language: generic
addons:
  apt:
    packages:
      - net-tools
script:
  - /sbin/ifconfig

That installs the net-tools package, then calls the ifconfig command that package adds.

In the output from that command, you want to look at the information for the eth0 interface:

eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:08  
          inet addr:172.17.0.8  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1245 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1083 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:17000256 (17.0 MB)  TX bytes:122513 (122.5 KB)

But it’s better these days to instead use the ip command from the iproute2 package:

dist: trusty
language: generic
addons:
  apt:
    packages:
      - iproute2
script:
  - ip a

Sample output:

10: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:05 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.5/16 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe11:5/64 scope link 
       valid_lft forever preferred_lft forever

Upvotes: 1

Related Questions