carp3/network-interfaces

一个简单的库,用于修改基于 Debian 的 /etc/network/interfaces 文件

dev-master 2019-07-25 19:05 UTC

This package is not auto-updated.

Last update: 2024-09-21 17:52:33 UTC


README

一个简单的 PHP 库,用于读取和操作基于 Debian 的发行版中 /etc/network/interfaces 文件。

安装

composer require carp3/network-interfaces

用法

<?php
//include composer autoloader
include 'vendor/autoload.php';

// 'import' NetworkInterfaces class
use NetworkInterfaces\Adaptor;
use NetworkInterfaces\NetworkInterfaces;

// create new handle from /etc/networking/interfaces
$handle = new NetworkInterfaces('/etc/networking/interfaces');

// parse file
$handle->parse();

// create new Adaptor and set configs
$adaptor = new Adaptor();
$adaptor->name = "eth2";
$adaptor->family = "inet";
$adaptor->name = "statis";
$adaptor->address = '192.168.2.100';
$adaptor->gateway = '192.168.2.1';
$adaptor->netmask = '255.255.255.0';
$adaptor->auto = true;
$adaptor->allows[] = 'hotplug';

// add adaptor to NetworkInterfaces instance
$handle->add($adaptor);


// change eth0 ip address
$handle->Adaptors['eth0']->address = '192.168.0.30';

// Write changes to /etc/networking/interfaces
$handle->write();

// bringing up new interface
$handle->up('eth2');