Sharing internet settings in Linux

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.