2016-09-22 12:43:57 +00:00
---
title: About the interface Resource
2018-02-16 00:28:15 +00:00
platform: os
2016-09-22 12:43:57 +00:00
---
# interface
2020-05-14 17:14:57 +00:00
Use the `interface` Chef InSpec audit resource to test basic network adapter properties, such as name, status, IP addresses, and link speed (in MB/sec).
2016-09-22 12:43:57 +00:00
* On Linux platforms, `/sys/class/net/#{iface}` is used as source
* On the Windows platform, the `Get-NetAdapter` cmdlet is used as source
2020-05-14 21:28:58 +00:00
* On BSD and MacOS platforms, the `ifconfig` command is used as source. Link speed may not be available.
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
<br>
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
2020-06-18 19:15:02 +00:00
This resource first became available in v1.0.0 of Chef InSpec.
2018-08-09 12:34:49 +00:00
2016-09-27 19:03:23 +00:00
## Syntax
2016-09-22 12:43:57 +00:00
An `interface` resource block declares network interface properties to be tested:
2017-05-18 19:28:19 +00:00
describe interface('eth0') do
2016-09-22 12:43:57 +00:00
it { should be_up }
its('speed') { should eq 1000 }
its('name') { should eq eth0 }
2020-05-14 17:14:57 +00:00
its('ipv4_addresses') { should include '10.0.0.5' }
2016-09-22 12:43:57 +00:00
end
2017-10-03 21:35:10 +00:00
<br>
2018-02-16 02:34:11 +00:00
2018-02-15 14:33:22 +00:00
## Properties
2016-09-22 12:43:57 +00:00
2020-05-19 03:42:25 +00:00
`ipv4_address`, `ipv4_addresses`, `ipv4_addresses_netmask`, `ipv4_cidrs`, `ipv6_addresses`, `ipv6_cidrs`, `name`, `speed`
2018-02-16 02:34:11 +00:00
2016-09-22 12:43:57 +00:00
2018-02-08 21:43:50 +00:00
## Resource Property Examples
2016-09-22 12:43:57 +00:00
2020-05-19 03:42:25 +00:00
### ipv4_address
2020-06-18 19:15:02 +00:00
Returns the first `ipv4_addresses` entry as a String. Note: this property is incompatible with ServerSpec, which returns the value including the CIDR range, such as '10.0.0.5/32'.
2020-05-19 03:42:25 +00:00
2020-06-05 17:48:41 +00:00
its('ipv4_address') { should eq '10.0.0.5' }
2020-05-19 03:42:25 +00:00
2019-03-18 22:53:51 +00:00
### ipv4_addresses
2020-05-14 17:14:57 +00:00
The `ipv4_addresses` property returns an Array of IPv4 addresses as Strings. You may then test if the specified address exists on the named network interface:
2019-03-18 22:53:51 +00:00
its('ipv4_addresses') { should include '127.0.0.1' }
2020-05-14 17:14:57 +00:00
### ipv4\_addresses\_netmask
2019-03-18 22:53:51 +00:00
2020-06-18 19:15:02 +00:00
The `ipv4_addresses_netmask` property returns an Array of Strings with each containing the IPv4 address, a slash, and the netmask. You may then test if the specified address and netmask exists on the named network interface:
2019-03-18 22:53:51 +00:00
its('ipv4_addresses_netmask') { should include '127.0.0.1/255.0.0.0' }
2020-05-19 03:42:25 +00:00
### ipv6_address
2020-06-05 17:48:41 +00:00
Returns the first `ipv6_address` entry. Note: this property is incompatible with ServerSpec, which returns the value including the CIDR range.
2020-05-19 03:42:25 +00:00
2020-06-05 17:48:41 +00:00
its('ipv6_address') { should eq '2089:98b::faeb' }
2020-05-19 03:42:25 +00:00
2019-03-18 22:53:51 +00:00
### ipv6_addresses
2020-05-14 17:14:57 +00:00
The `ipv6_addresses` property returns an Array of Strings and tests if the specified address exists on the named network interface:
2019-03-18 22:53:51 +00:00
its('ipv6_addresses') { should include '::1' }
### ipv4_cidrs
2020-05-14 17:14:57 +00:00
The `ipv4_cidrs` property returns an Array of Strings and tests if the specified address and netmask combination exists on the named network interface:
2019-03-18 22:53:51 +00:00
its('ipv4_cidrs') { should include '127.0.0.1/8' }
### ipv6_cidrs
2020-05-14 17:14:57 +00:00
The `ipv6_cidrs` property returns an Array of Strings and tests if the specified address and netmask combination exists on the named network interface:
2019-03-18 22:53:51 +00:00
its('ipv6_cidrs') { should include '::1/128' }
2020-05-14 17:14:57 +00:00
### name
The `name` property returns the name of the interface:
its('name') { should eq 'eth0' }
### speed
2020-05-14 21:28:58 +00:00
The `speed` property tests the speed of the network interface, in MB/sec. Note: On BSD and MacOS platforms, this value may be nil, because it difficult to obtain reliably.
2020-05-14 17:14:57 +00:00
its('speed') { should eq 1000 }
2018-02-08 21:43:50 +00:00
## Matchers
2018-02-16 03:07:18 +00:00
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2018-02-08 21:43:50 +00:00
### be_up
The `be_up` matcher tests if the network interface is available:
it { should be_up }
2020-05-14 17:14:57 +00:00
### exist
The `exist` matcher tests if the network interface exists:
it { should exist }
### have\_an\_ipv4\_address
2019-03-18 22:53:51 +00:00
The `have_an_ipv4_address` matcher tests if the network interface has any IPv4 addresses assigned:
it { should have_an_ipv4_address }
2020-05-14 17:14:57 +00:00
### have\_an\_ipv6\_address
2019-03-18 22:53:51 +00:00
The `have_an_ipv6_address` matcher tests if the network interface has any IPv6 addresses assigned:
it { should have_an_ipv6_address }