多多益善什么意思| 白细胞高有什么危害| 梦见剃光头是什么预兆| who医学上是什么意思| 目赤什么意思| 麻醉学学什么| 裘皮是什么皮| 亚临床甲减是什么意思| 垂髫是什么意思| 鲍鱼长什么样| 空调买什么牌子好| 樵是什么意思| 女性内分泌失调有什么症状| 枸杞子有什么功效| 迅速的反义词是什么| 鲜花什么| 孕妇吃什么对胎儿好| 不遗余力什么意思| 检查尿常规挂什么科| 胃酸烧心吃什么药| 鸡五行属什么| 短兵相见是什么意思| 手指尖疼是什么原因| 下一个台风什么时候来| 1993年什么命| 脾胃气滞吃什么中成药| 胎儿颈部可见u型压迹什么意思| 节律是什么意思| 下肢肿胀是什么原因| 际遇是什么意思| 头发出油是什么原因| 每天坚持做俯卧撑有什么好处| 乳腺增生吃什么药好| 满清是什么民族| 心形脸适合什么发型| 焦虑挂什么科| 胎头位于耻上是什么意思| 毛五行属什么| 善存片什么时候吃最好| 聚乙二醇400是什么| 左肾轻度积水是什么意思| nova是什么牌子| 什么东西人们都不喜欢吃| 稀饭和粥有什么区别| seifini是什么牌子| 2月14日是什么星座| 去医院点痣挂什么科| 什么情况下需要做喉镜检查| 8月5日什么星座| 甲方是什么意思| 问加一笔是什么字| 八年是什么婚| 少将相当于什么级别| 鱼油吃多了有什么副作用| 伤寒现在叫什么病| 不言而喻是什么意思| 血压忽高忽低是什么原因| 无住生心是什么意思| 尿蛋白可疑阳性是什么意思| 什么时间容易受孕| 胃萎缩是什么原因| 南非叶有什么功效| 五月是什么星座| 农历4月是什么星座| 送女生什么生日礼物比较好| 阴囊潮湿吃什么药| 检验科是做什么的| 吃什么精力旺盛有精神| 鼻子上长脓包型痘痘是什么原因| 怕金病帕金森是什么症状| 书到用时方恨少下一句是什么| se是什么国家| 什么人不建议吃海参| s2是什么意思| 手指盖空了是什么原因| 大黄蜂是什么车| 丁字五行属什么| 属鼠的和什么属相相克| 酷暑难当是什么意思| 穿什么好呢| 未可以加什么偏旁| 臆想什么意思| 感冒了吃什么好的快| 兜售是什么意思| 鼻炎是什么引起的| 手小的男人代表什么| lancome是什么品牌| 性价比高什么意思| 大自然是什么意思| 什么手机性价比高| 三八妇女节是什么生肖| 开心水是什么| ct挂什么科| 虎鼠不结亲是什么意思| 肾结石吃什么药止疼| 网黄什么意思| 心里发慌什么原因| 关帝庙求什么最灵| 制服是什么意思| sunnyday是什么意思| scarves什么意思| 鹌鹑吃什么| cd代表什么意思| 中国最高学历是什么| 痛风该吃什么药好得快| 弄虚作假是什么生肖| 番薯什么时候传入中国| 5月7日什么星座| 罗布麻是什么东西| 梦见车丢了是什么征兆| lively是什么意思| 忍者神龟是什么意思| emma是什么意思| 什么病属于重大疾病| 宝字五行属什么| 合寿木是什么意思| 看肝脏挂什么科| 征字五行属什么| 二郎神是什么生肖| 半边脸肿是什么原因引起的| 面瘫吃什么药好| 例假推迟是什么原因引起的| 洗手做羹汤是什么意思| 过期的维生素e有什么用途| 白羊女喜欢什么样的男生| 壁立千仞无欲则刚是什么意思| aquascutum是什么牌子| 耳毛念什么| 砥砺什么意思| 黄痰吃什么药| 早退是什么意思| 草莓的种子是什么| 伤官女是什么意思| 属牛男和什么属相最配| 查高血压挂什么科| 什么叫2型糖尿病| 出水痘吃什么药| 交易是什么意思| 辅警是什么| 什么食物含维生素k最多| pr是什么职位| 开宠物医院需要什么条件| 盆腔积液吃什么药效果最好| 1994年属什么生肖| 阴影是什么意思| 心脏问题挂什么科| 1991是什么年| 李健是清华什么专业| acs是什么病| 下巴下面长痘痘是什么原因| 喉咙痒咳嗽吃什么药好| 床头朝什么方向是正确的| 15年婚姻是什么婚| nothomme什么牌子| 理想血压是什么意思| 头顶疼是什么原因引起的| 栀子花开有什么寓意| 又什么又什么式的词语| 总是困是什么原因| 肉燕是什么做的| 倒刺是什么原因引起的| 自带bgm是什么意思| 墨龟为什么只能养一只| 什么的雨丝| 什么是优质蛋白食物| 爱而不得是什么感觉| 什么是bg| 怀孕是什么意思| 儿童吃手指是什么原因| 粉色是什么颜色| b2b是什么意思| 真性情是什么意思| 五味子是什么| 维生素b补什么的| 睡觉流口水是什么原因引起的| 龟龟是什么意思| 切痣挂什么科| 什么克风| 小暑节气吃什么| 南非叶主治什么病| 糖尿病人能吃什么| 三七粉什么人不适合吃| 什么态度| 品行是什么意思| 胎停是什么原因引起的| 西葫芦不能和什么一起吃| 核桃补什么| 字什么意思| 心慌手抖是什么原因| 多喝水有什么好处和坏处| 双子座是什么星座| 什么拂面| 熬夜吃什么补回来| 脱发用什么药最好| 1211是什么星座| 脉搏细是什么原因| 34是什么意思| 脚有酸味是什么原因| 翻来覆去的覆什么意思| 真金白银是什么意思| 三公是什么意思| poscer是什么牌子手表| 什么的歌声填词语| 小米不能和什么一起吃| 2019属什么| 什么运动有助于长高| 后背疼是什么原因引起的| 什么是脑白质病| 虎头蜂泡酒有什么功效| 女性白带有血丝是什么原因| 风象星座是什么意思| 阴茎疱疹用什么药| 1933年属什么生肖| 散光轴位是什么| np是什么| 蜜蜂为什么会蜇人| 梦见鱼是什么意思| 月经不调吃什么药调理最好| 尖斌卡引是什么意思| 木星是什么颜色| 朱迅是什么民族| 高危行为是什么意思| 鬼门关是什么意思| 尿潴留是什么原因引起的| 水杯什么品牌好| 开光的手串有什么禁忌| 重庆什么时候解放的| 眼白有黄斑是什么原因| 妈祖是什么| 88年出生属什么生肖| 十月十四是什么星座| 比围是什么| 梦到和别人吵架是什么意思| 四个一是什么| 9月是什么季节| 手脚脱皮吃什么维生素| 史字五行属什么| 人为什么要吃盐| 真情流露是什么意思| 毕业送什么花| 男士圆脸适合什么发型| 莘莘学子什么意思| 玛瑙是什么| 为什么会突然长痣| 什么情况下月经推迟| 做酸菜鱼用什么鱼| 梦见假牙掉了是什么意思| 蹦迪是什么意思| 斯文败类是什么意思| 产后为什么脸部松弛| 喜形于色是什么意思| 勇者胜的上半句是什么| 乌龙茶适合什么季节喝| newbee什么意思| zw是什么意思| 蓝光有什么作用| 秋高气爽是什么意思| 了解是什么意思| 精神病是什么意思| 阴道炎是什么原因引起的| 胆汁什么颜色| 生肖羊和什么生肖相冲| 不想吃饭没胃口是什么原因| 经常咳嗽是什么原因| 百度
Jump to content

宁化有家“免费互助”餐厅 可免费用餐必须“光...

From ArchWiki

This article explains how to share the internet connection from one machine to other(s).

Requirements

The machine acting as server should have an additional network device, aka network interface. That network device requires a functional data link layer to the machine(s) that are going to receive internet access:

  • To be able to share internet to several machines a switch can provide the data link layer connection.
  • A wireless device can share access to several machines as well, see Software access point first for this case.
  • If you are sharing to only one machine, a crossover cable is sufficient. In case one of the two computers' Ethernet cards has auto MDI-X capability, a crossover cable is not necessary and a regular Ethernet cable can be used. Executing ethtool interface | grep MDI as root helps to figure it. You might be able to proceed even if that command gives you errors or does not find anything on either machine and you do not have a crossover cable.

Configuration

Note: This section assumes that the network device connected to the client computer(s) is named net0 and the network device connected to the internet is internet0.
Tip: You can rename your devices to this scheme using udev#Setting static device names.

All configuration is done on the server computer, except for the final step of #Assigning IP addresses to the client PC(s).

Static IP address

On the server computer, assign a static IPv4 address to the interface connected to the other machines. The first 3 bytes of this address cannot be exactly the same as those of another interface, unless both interfaces have netmasks strictly greater than /24.

# ip link set up dev net0
# ip addr add 192.168.123.100/24 dev net0 # arbitrary address

To have your static IP assigned at boot, you can use a network manager.

Enable packet forwarding

Warning: Enabling IP forwarding without a properly configured firewall is a security risk.

To check the current packet forwarding settings, run:

# sysctl -a | grep forward

You will note options for controlling forwarding per default, per interface, as well as separate options for IPv4/IPv6 per interface. For detailed description of all available options, see the kernel documentation.

To enable IPv4 and IPv6 packet forwarding, configure sysctl to set these settings:

net.ipv4.ip_forward = 1
net.ipv4.conf.all.forwarding = 1
net.ipv6.conf.all.forwarding = 1
Tip: To enable packet forwarding selectively for a specific interface, use net.ipv[46].conf.interface_name.forwarding=1 instead.
Warning:

This article or section is out of date.

Reason: Most likely outdated. As systemd-networkd 256+ now supports setting IPv4Fowarding on a per link level. Please delete this Note, and below warning on confirmation. (Discuss in Talk:Internet sharing)

If the system uses systemd-networkd to control the network interfaces, a per-interface setting for IPv4 is not possible, i.e. systemd logic propagates any configured forwarding into a global (for all interfaces) setting for IPv4. The advised work-around is to use a firewall to forbid forwarding again on selective interfaces. See the systemd.network(5) manual page for more information. The IPForward=kernel semantics introduced in a previous systemd release 220/221 to honor kernel settings does not apply anymore.[1] [2]

To make changes persistent across reboots, see Sysctl#Configuration. You might consider writing settings to a file with a descriptive filename, such as /etc/sysctl.d/30-ipforward.conf.

Afterwards it is advisable to double-check forwarding is enabled as required after a reboot.

Packet forwarding with systemd-networkd

This article or section is a candidate for merging with systemd-networkd#[Network].

Notes: An arbitrary file naming does not make sense for a generic example. A .network file without a [Match] section does not make sense. Simply say what needs to be set and link to the systemd-networkd#[Network] page. (Discuss in Talk:Internet sharing)

If you are using systemd-networkd to manage your network configuration, you can also persist those settings across reboots:

/etc/systemd/network/20-lan.network
[Network]
IPv4Forwarding=yes
...

This essentially sets the same net.ipv[46].conf.interface_name.forwarding=1 as mentioned in previous section. For IPv6 the configuration is IPv6Forwarding=yes.

Note: As of systemd 256, the IPv6Forwarding option does not behave as documented, see [3].

This sets up packet forwarding for the specific interface only. For internet sharing to properly work, you need to enable packet forwarding on both (all) interfaces where traffic should be routed between. Typically your lan and wan interfaces.

See also systemd-networkd#[Network].

Enable NAT

Besides the methods listed here, its also possible to use ufw to set up a NAT.

With iptables

Install the iptables package. Use iptables to enable NAT:

# iptables -t nat -A POSTROUTING -o internet0 -j MASQUERADE
# iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# iptables -A FORWARD -i net0 -o internet0 -j ACCEPT
Note: Of course, this also works with a mobile broadband connection (usually called ppp0 on routing PC).

Use -I DOCKER-USER instead of -A FORWARD if you installed docker. [4]

# iptables -t nat -A POSTROUTING -o internet0 -j MASQUERADE
# iptables -I DOCKER-USER 1 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# iptables -I DOCKER-USER 2 -i net0 -o internet0 -j ACCEPT

If connected via PPPoE, clamp mss to pmtu in order to prevent fragmentation:

# iptables -t mangle -A FORWARD -o ppp0 -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

Read the iptables article for more information (especially saving the rule and applying it automatically on boot). There is also an excellent guide on iptables Simple stateful firewall.

With nftables

Install the nftables package. To enable NAT with nftables, you will have to create the postrouting chain in a new/existing table:

# nft add table inet nat
# nft add chain inet nat postrouting '{ type nat hook postrouting priority srcnat ; }'

After that, you have to masquerade the net0 addresses for internet0:

# nft add rule inet nat postrouting oifname internet0 masquerade

Many firewall configurations, like the default /etc/nftables.conf, set the default policy of the 'filter' table's 'forward' chain to 'drop'. In such cases, you will need rules to allow forwarding NAT traffic:

# nft add rule inet filter forward ct state related,established accept
# nft add rule inet filter forward iifname net0 oifname internet0 accept
Tip: When using systemd-networkd, use dynamic named sets (NFTSet=) to avoid hardcoding interface names in nftables rules.

You can find more information on NAT in nftables in the nftables Wiki. If you want to make these changes permanent, follow the instructions on nftables.

With firewalld

Install the firewalld package. firewalld is a firewall daemon which relies on nftables or iptables. First change the firewalld zones of network interfaces:

# firewall-cmd --zone=external --change-interface=internet0 --permanent
# firewall-cmd --zone=internal --change-interface=net0 --permanent

Then add a new policy to let traffic flow between the internal and external zone:

# firewall-cmd --permanent --new-policy int2ext
# firewall-cmd --permanent --policy int2ext --add-ingress-zone internal
# firewall-cmd --permanent --policy int2ext --add-egress-zone external
# firewall-cmd --permanent --policy int2ext --set-target ACCEPT
# firewall-cmd --reload
Tip: You can use stricter policy rules than bare ACCEPT as illustrated in the Firewall Rules section of the firewalld concept page[5]

For example, to allow only nodes in 192.168.2.0/24 to access the internet, do:

firewall-cmd --permanent --policy int2ext --add-rich-rule='rule family=ipv4 source address=192.168.2.0/24 accept' Do not forget to reload rules afterwards:

firewall-cmd --reload

Assigning IP addresses to the client PC(s)

If you are planning to regularly have several machines using the internet shared by this machine, then is a good idea to install a DHCP server. See Router#DNS and DHCP for the available options. Then configure a DHCP client on every client PC, see Network configuration#Network managers.

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: This is not an iptables guide. Expanding the chain with iptables -I might skip other important rules; if you need to script an ON/OFF switch for this, use custom chain with a jump placed carefully in the INPUT chain. (Discuss in Talk:Internet sharing)

Incoming connections to UDP port 67 has to be allowed for DHCP server. It also necessary to allow incoming connections to UDP/TCP port 53 for DNS requests.

# iptables -I INPUT -p udp --dport 67 -i net0 -j ACCEPT
# iptables -I INPUT -p udp --dport 53 -s 192.168.123.0/24 -j ACCEPT
# iptables -I INPUT -p tcp --dport 53 -s 192.168.123.0/24 -j ACCEPT

Alternatively using firewalld

# firewall-cmd --zone=internal --permanent --add-service dns
# firewall-cmd --zone=internal --permanent --add-service dhcp
# firewall-cmd --zone=internal --permanent --add-service dhcpv6

If you are not planning to use this setup regularly, you can manually add an IP to each client instead.

Manually adding an IP

Instead of using DHCP, a static IP address and a default route via 192.168.123.100 can also be configured manually. There are many tools available to configure the network accordingly. One prominent example of such a tool is ip(8), see Network configuration#Network management. Alternatively, one can use a .network file, see Systemd-networkd#Wired adapter using a static IP to setup a static IP.

Configure a DNS server for each client, see Domain name resolution for details.

That is it. The client PC should now have Internet.

Troubleshooting

If you are able to connect the two PCs but cannot send data (for example, if the client PC makes a DHCP request to the server PC, the server PC receives the request and offers an IP to the client, but the client does not accept it, timing out instead), check that you do not have other iptables rules interfering.

Clients cannot access the internet or cannot connect

Symptoms might also include: Clients get host is down when pinging host, gets no route to host or Destination Host Unreachable when pinging devices outside the LAN (that should be forwarded by NAT), DHCP offers not crossing a bridge, ...

It is known that docker may cause these problems. Simply disabling docker.service and docker.socket solves this problem.

docker github issue.

Connected second PC unable to use bridged LAN

First PC have two LANs. Second PC have one LAN and connected to first PC. Lets go second PC to give all access to LAN after bridged interface:

This article or section needs expansion.

Reason: Explain what the settings actually do. (Discuss in Talk:Internet sharing)
# sysctl net.bridge.bridge-nf-filter-pppoe-tagged=0
# sysctl net.bridge.bridge-nf-filter-vlan-tagged=0
# sysctl net.bridge.bridge-nf-call-ip6tables=0
# sysctl net.bridge.bridge-nf-call-iptables=0
# sysctl net.bridge.bridge-nf-call-arptables=0

See also

异想天开是什么意思 角的大小和什么有关 大人积食吃什么药 低密度脂蛋白偏低是什么意思 口腔医学专业学什么
手背上长痣代表什么 网拍是什么意思 忤逆是什么意思 孩子流黄鼻涕吃什么药效果好 出去旅游需要带什么
氨咖黄敏胶囊是什么药 4.22什么星座 淋巴结肿大有什么症状 八一建军节是什么节日 虫字旁的字和什么有关
茅台为什么这么贵 吃完油炸的东西后吃什么化解 20年是什么婚 紫五行属什么 为什么月经迟迟不来又没怀孕
脉搏是什么意思hcv9jop2ns4r.cn 萎缩性胃炎可以吃什么水果hcv8jop4ns5r.cn 不全纵隔子宫是什么意思hkuteam.com 碱性磷酸酶高吃什么药hcv7jop7ns2r.cn 怎么知道自己对什么过敏hcv8jop6ns1r.cn
legion什么牌子hcv8jop1ns2r.cn 梦见割草是什么意思jingluanji.com 出cos是什么意思hcv8jop2ns3r.cn 梅毒什么症状luyiluode.com ky是什么hcv7jop4ns6r.cn
强阳下降到什么程度开始排卵hcv7jop5ns1r.cn 梯是什么意思hcv9jop5ns7r.cn 女人吃什么增加雌激素hcv8jop0ns9r.cn 突然戒烟对身体有什么影响mmeoe.com 小便痒痒是什么原因女hcv9jop1ns9r.cn
阴骘什么意思hcv7jop7ns3r.cn 汗斑用什么药膏好hcv8jop6ns5r.cn 脚发痒是什么原因hcv8jop5ns1r.cn 唐氏综合症是什么原因hcv9jop2ns2r.cn 胎先露是什么意思hcv7jop9ns9r.cn
百度