ubuntu でネットワーク インターフェイスを構成する必要があります。これは私のコードです
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package epsetupserv.network;
import epsetupapi.entity.NetworkEntity;
import epsetupserv.config.GeneralConfigurator;
import epsetupserv.lib.FileOperation;
import epsetupserv.lib.ShellAccess;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author nununeh
*/
public class NetworkConfigurator {
private static String realPath = "/etc/network/";
private static String realFile = "interface";
public static List<NetworkEntity> getRealNetworkInterface() {
List<NetworkEntity> list = new ArrayList<NetworkEntity>();
int eth0_loc = FileOperation.findStringLine(realPath, realFile, "auto eth0");
int eth1_loc = FileOperation.findStringLine(realPath, realFile, "auto eth1");
int tline = FileOperation.countLine(realPath, realPath);
GeneralConfigurator gn = new GeneralConfigurator(realPath, realFile);
gn.setDelimiter(" ");
NetworkEntity n1 = new NetworkEntity();
n1.setAddress(gn.getProperty("address", eth0_loc, eth1_loc));
n1.setNetmask(gn.getProperty("netmask", eth0_loc, eth1_loc));
n1.setNetwork(gn.getProperty("network", eth0_loc, eth1_loc));
n1.setBroadcast(gn.getProperty("broadcast", eth0_loc, eth1_loc));
list.add(n1);
NetworkEntity n2 = new NetworkEntity();
n2.setAddress(gn.getProperty("address", eth1_loc, tline));
n2.setNetmask(gn.getProperty("netmask", eth1_loc, tline));
n2.setNetwork(gn.getProperty("network", eth1_loc, tline));
n2.setBroadcast(gn.getProperty("broadcast", eth1_loc, tline));
list.add(n2);
return list;
}
public static void setRealNetworkInterface(NetworkEntity n1, NetworkEntity n2) {
int tline = FileOperation.countLine(realPath, realFile);
FileOperation.clearByLine(realPath, realFile, 1, tline);
FileOperation.insertNewLine(realPath, realFile, ""
+ "# Generated By ePanel\\nn"
+ "auto lo\n"
+ "iface lo inet loopback\n"
+ "\n"
+ "auto eth0\n"
+ "iface eth0 inet static\n"
+ " address " + n1.getAddress() + "\n"
+ " netmask " + n1.getNetmask() + "\n"
+ " network " + n1.getNetwork() + "\n"
+ " broadcast " + n1.getBroadcast() + "\n"
+ "\n"
+ "auto eth1\n"
+ "iface eth1 inet static\n"
+ " address " + n2.getAddress() + "\n"
+ " netmask " + n2.getNetmask() + "\n"
+ " network " + n2.getNetwork() + "\n"
+ " broadcast " + n2.getBroadcast() + "\n");
}
}
クラスを使用するときの問題は、プロパティを 1 つずつ変更できないことです。したがって、eth1 からアドレスのみを変更したい場合は、1 回のプロセス実行ですべてを変更する必要があります (eth0 と eth1 の下のすべてのプロパティ)。代替コードはありますか?