LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-27-2015, 12:31 PM   #1
bryn1u
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Rep: Reputation: Disabled
[Centos 7] Router with 2 interfaces


Hello everyone,

I'm trying to share internet for client laptop based on windows 7. My router is second laptop based on centos 7 and connected to Wifi ISP router/modem (192.168.0.1).
I have to interfaces:
wlp6s0 - my router interfaces which im getting internet from ISP by wifi
Code:
wlp6s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.6  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::222:fbff:fe95:a9e  prefixlen 64  scopeid 0x20<link>
        ether 00:22:fb:95:0a:9e  txqueuelen 1000  (Ethernet)
        RX packets 10706  bytes 10082336 (9.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8470  bytes 1152596 (1.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
And second:
Code:
enp8s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:1d:ba:f6:a3:ef  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16
enp8s0 is my second card, ethernet. This way i want to share internet for client laptop with windows 7.

I configured ifcfg-enp8s0 :
Code:
[root@localhost sysconfig]# cd network-scripts/
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@localhost network-scripts]# cat ifcfg-enp8s0 
DEVICE=enp8s0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.33
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=192.168.0.1

[root@localhost network-scripts]#
But when i reboot my router i dont get it any changes for enp8s0, no ip, no mask etc.
After reboot:
Code:
enp8s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:1d:ba:f6:a3:ef  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16
ISP/Router WiFi 192.168.0.1 <------> (192.168.0.6 wlp6s0) my laptop router with Centos 7 (enp8s0 - second interface) <----> my laptop with windows 7

How can i share internet for laptop with win 7. I've tried many ways but i still cant do this (

Someone can help ?

Greetz,
 
Old 12-27-2015, 01:02 PM   #2
v4r3l0v
Member
 
Registered: Dec 2013
Posts: 136

Rep: Reputation: Disabled
Provided that your wired ethernet card is connected to your router:
nmcli con show --active

to see which CONNECTIONS are up instead of just looking at devices that are up.

nmcli con up ifcfg-enp8s0 to bring your connection that you want to share with Windows 7 machine.

There's a bit more to it than just fixing addressing on NIC's in order to use your machine as a router on the network. But let's get this connection working first.

Last edited by v4r3l0v; 12-27-2015 at 01:04 PM.
 
Old 12-27-2015, 01:09 PM   #3
bryn1u
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by v4r3l0v View Post
Provided that your wired ethernet card is connected to your router:
nmcli con show --active

to see which CONNECTIONS are up instead of just looking at devices that are up.

nmcli con up ifcfg-enp8s0 to bring your connection that you want to share with Windows 7 machine.

There's a bit more to it than just fixing addressing on NIC's in order to use your machine as a router on the network. But let's get this connection working first.
Hey,

Thanks for your replay.

I know which connections are up:
Code:
[root@localhost network-scripts]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp8s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether 00:1d:ba:f6:a3:ef brd ff:ff:ff:ff:ff:ff
3: wlp6s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:22:fb:95:0a:9e brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.6/24 brd 192.168.0.255 scope global dynamic wlp6s0
       valid_lft 82193sec preferred_lft 82193sec
    inet6 fe80::222:fbff:fe95:a9e/64 scope link 
       valid_lft forever preferred_lft forever
nmcli
Code:
[root@localhost network-scripts]# nmcli connection show --active
NAZWA     UUID                                  TYP              URZDZENIE 
Ryszarda  40e22019-04c1-487e-a0f7-f6c70020bd30  802-11-wireless  wlp6s0
Ehh something is wrong
Code:
[root@localhost network-scripts]# ip link set enp8s0 up
[root@localhost network-scripts]# nmcli connection show --active
NAZWA     UUID                                  TYP              URZDZENIE 
Ryszarda  40e22019-04c1-487e-a0f7-f6c70020bd30  802-11-wireless  wlp6s0     
[root@localhost network-scripts]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp8s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether 00:1d:ba:f6:a3:ef brd ff:ff:ff:ff:ff:ff
3: wlp6s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:22:fb:95:0a:9e brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.6/24 brd 192.168.0.255 scope global dynamic wlp6s0
       valid_lft 81988sec preferred_lft 81988sec
    inet6 fe80::222:fbff:fe95:a9e/64 scope link 
       valid_lft forever preferred_lft forever
enp8s0 doesn't want to up

Last edited by bryn1u; 12-27-2015 at 01:11 PM.
 
Old 12-27-2015, 01:29 PM   #4
v4r3l0v
Member
 
Registered: Dec 2013
Posts: 136

Rep: Reputation: Disabled
You need to plug in the network cable on both ends: your CentOS machine and your Windows machine. That cable can't be of the same type that you usually use to connect from computer to router. It has to be a cross-over cable. Windows machine also has to be turned on.
 
Old 12-27-2015, 01:45 PM   #5
bryn1u
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Yes, u have totally right !

Now, seems to be okey.

Code:
[root@localhost network-scripts]# ifconfig -a
enp8s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.33  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::21d:baff:fef6:a3ef  prefixlen 64  scopeid 0x20<link>
        ether 00:1d:ba:f6:a3:ef  txqueuelen 1000  (Ethernet)
        RX packets 128  bytes 20919 (20.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 123  bytes 9475 (9.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16
Is it all ? Do i need something more ?

#edit
Whan i turn on enp8s0 i cant get access to the internet from laptop/router. When i turned off works well. What happened ?

Last edited by bryn1u; 12-27-2015 at 01:47 PM. Reason: my bad
 
Old 12-27-2015, 02:25 PM   #6
v4r3l0v
Member
 
Registered: Dec 2013
Posts: 136

Rep: Reputation: Disabled
For routing internet connection from your CentOS to your Windows to happen, you need to do few more things on both machines then just plug cables in.
On CentOS, you need to enable routing and set up masquerading in firewall.
On Windows, you need to setup your CentOS machine as a gateway/default route for Windows.
On router, you need to reserve the static IP that you'll give to your CentOS machine. And you need static IP for CentOS, gateway cannot be a moving target.
On CentOS, locate the file /etc/sysctl.d/99-sysctl.conf and in it write:
Quote:
net.ipv4.ip_forward=1
Next, see which firewalld zone controls which network interface:
Quote:
firewall-cmd --get-zone-of-interface=enp8s0
firewall-cmd --get-zone-of-interface=whatever the name of your wireless card is
Are they on same zone? Switch them to a different zone to apply masquerading later and complete the routing phase:
Quote:
firewall-cmd --permanent --zone=internal --change-interface=enp8s0
Let's say your wireles card is in zone "public". Aplly the masquerade and be done with routing:
Quote:
firewall-cmd --permanent --zone=public --add-masquerade
Reload firewalld to make all these changes to take effect:
Quote:
firewall-cmd reload
And maybe restart networking: systemctl restart network
On Windows, from the top of my head, I can't recall how do you go about setting up static IP and gateway but I'm sure you can research it in less than two minutes on a search engine. I haven't done networking stuff on Windows in a long time.
On router, these consumer-grade routers have web interfaces that allow you to also reserve the static IP of your CentOS machine.

Last edited by v4r3l0v; 12-27-2015 at 02:27 PM.
 
Old 12-29-2015, 03:37 PM   #7
bryn1u
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by v4r3l0v View Post
For routing internet connection from your CentOS to your Windows to happen, you need to do few more things on both machines then just plug cables in.
On CentOS, you need to enable routing and set up masquerading in firewall.
On Windows, you need to setup your CentOS machine as a gateway/default route for Windows.
On router, you need to reserve the static IP that you'll give to your CentOS machine. And you need static IP for CentOS, gateway cannot be a moving target.
On CentOS, locate the file /etc/sysctl.d/99-sysctl.conf and in it write:

Next, see which firewalld zone controls which network interface:

Are they on same zone? Switch them to a different zone to apply masquerading later and complete the routing phase:

Let's say your wireles card is in zone "public". Aplly the masquerade and be done with routing:

Reload firewalld to make all these changes to take effect:

And maybe restart networking: systemctl restart network
On Windows, from the top of my head, I can't recall how do you go about setting up static IP and gateway but I'm sure you can research it in less than two minutes on a search engine. I haven't done networking stuff on Windows in a long time.
On router, these consumer-grade routers have web interfaces that allow you to also reserve the static IP of your CentOS machine.
Thank u for answer. I really appreciate your commitment to this topic
I was wondering if can i use "ip route" instead firewalld ?
 
Old 12-29-2015, 03:39 PM   #8
v4r3l0v
Member
 
Registered: Dec 2013
Posts: 136

Rep: Reputation: Disabled
You are very welcome.
Anything done with the ip command is not persistent. After you reboot, those changes will be lost.
 
Old 01-10-2016, 05:41 AM   #9
bryn1u
LQ Newbie
 
Registered: Feb 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by v4r3l0v View Post
You are very welcome.
Anything done with the ip command is not persistent. After you reboot, those changes will be lost.
Yes i know, but i want to learn. I'm trying send packet to last router. I don't know what's wrong.

Laptop Windows 7 192.168.0.11 <-----> 192.168.0.33 (enp8s0) | Laptop Centos 7 | (wlp6s0) 192.168.0.2 <-----> 192.168.0.1 (ISP Router) 100.91.*.* ----> World

ip route show
Code:
[root@localhost sysconfig]# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 wlp6s0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 wlp6s0
[root@localhost sysconfig]# 
[root@localhost sysconfig]#
Ping from Laptop Windows 7 to 192.168.33 works and to 192.168.0.2 works to and vice versa, but i cant ping 192.168.0.1 from Laptop Windows 7
What am i doing wrong ?
Code:
[root@localhost sysconfig]# ip route s
default via 192.168.0.1 dev wlp6s0  proto static  metric 600 
192.168.0.0/24 dev wlp6s0  proto kernel  scope link  src 192.168.0.2  metric 600
Code:
[root@localhost sysconfig]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:1d:ba:f6:a3:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.33/24 brd 192.168.0.255 scope global enp8s0
       valid_lft forever preferred_lft forever
    inet6 fe80::21d:baff:fef6:a3ef/64 scope link 
       valid_lft forever preferred_lft forever
3: wlp6s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:22:fb:95:0a:9e brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.2/24 brd 192.168.0.255 scope global dynamic wlp6s0
       valid_lft 75895sec preferred_lft 75895sec
    inet6 fe80::222:fbff:fe95:a9e/64 scope link 
       valid_lft forever preferred_lft forever
Greetz,

Last edited by bryn1u; 01-10-2016 at 05:42 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Router command line interfaces keepStriving Linux - Networking 2 08-07-2013 07:51 PM
Linux router MTU between 2 interfaces dot_txt Linux - Networking 1 03-25-2011 05:51 AM
Multible network interfaces, router settings? asl1176 Linux - Networking 3 11-22-2010 07:35 AM
Bridged Interfaces in CentOS snq Linux - Networking 1 11-21-2010 12:24 AM
problem with linux router with 2 interfaces arty Linux - Networking 6 07-01-2009 05:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration