Article Title: Sharing internet access settings in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Environment: A Linux machine has a single Nic, a window machine has a single NIC, and a four-port hub.
Background: The landlord only provides one network cable and limits that only one network card can be used to access the Internet (that is, the network card of my Linux machine ).
Objective: to bring the Windows machine into the network through Linux Internet sharing settings.
Method: use a Linux machine as a DHCP server and a hub as a LAN. Then forward the IP request for this CIDR block.
Create a Linux DHCP server. For Ubuntu
# Apt-get install dhcpd
After the installation is complete, change the/etc/dhcpd. conf file and add:
Option domain-name-servers 202.96.134.188, 202.96.134.20;
Default-lease-time 600;
Max-lease-time 7200;
Subnet 192.168.1.0 netmask 255.255.255.0 {
Range 192.168.1.2 192.168.1.200;
Option routers 192.168.20.1;
}
DHCP settings are complete. Next we need to set one more IP address for the Linux host and set IPtable rules.
Sudo ifconfig eth0: 1 192.168.20.1
Sudo sh-c "echo 1>/proc/sys/net/ipv4/ip_forward"
Sudo iptables-a forward-s 192.168.20.0/24-j ACCEPT
Sudo iptables-a forward-I eth0-m state? State ESTABLISHED, RELATED-j ACCEPT
You can write the preceding statement into a script. If necessary, the sharing function is enabled.
The window machine only needs to be set to automatically get the IP address (or set to 192.168.20.x network segment, and the gateway is 192.168.20.1 ). The physical connection is through the hub.
Each person's situation is different. you can modify it based on your own situation.