-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_configure_ethernet_bridge.sh
executable file
·66 lines (46 loc) · 1.78 KB
/
linux_configure_ethernet_bridge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
exit 1
##### méthode plus générique
# sur le pc a configurer une fois
yay -S --needed hostapd
sudo dnsmasq hostapd
sudo systemctl stop dnsmasq
sudo systemctl stop dhcpcd ou hostapd
nano /etc/dhcpcd.conf
interface enp3s25 #nom de l'interface ethernet
static ip_address=192.168.5.1/24
nano /etc/dnsmasq.conf
interface=enp3s25
dhcp-range=192.168.5.20,192.168.5.40,255.255.255.0,24h
dhcp-host=mac,ip
# pour démarrer le pont
sudo systemctl start dnsmasq
sudo systemctl start dhcpcd
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wlo1 -j MASQUERADE
iptables -A FORWARD -i enp3s0 -o wlo1 -j ACCEPT
iptables -A FORWARD -i wlo1 -o enp3s0 -m state --state RELATED,ESTABLISHED -j ACCEPT
#pour un accès depuis l'extérieur ramplacer la dernière ligne par:
iptables -A FORWARD -i wlo1 -o enp3s0 -j ACCEPT
# depuis un pc sur un réseau extérieur:
route add -net 192.168.4.0 netmask 255.255.255.0 gw 192.168.0.94
réseau et ip du pc qui fait le pont
###############################################################################
##### méthode rudimentaire
cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto eth0
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.2
dns-nameservers 1.1.1.1 9.9.9.9
# regler l'ip du pc sur 192.168.1.2
# et executer a chaque démarrage pour accéder à internet depuis la carte
#(changer le nom des interfaces si nécessaire)
sudo echo 1 > /proc/sys/net/ipv4/ip_forward
sudo iptables -t nat -A POSTROUTING -o wlo1 -j MASQUERADE
sudo iptables -A FORWARD -i enp3s0 -o wlo1 -j ACCEPT
sudo iptables -A FORWARD -i wlo1 -o enp3s0 -m state --state RELATED,ESTABLISHED -j ACCEPT