Setup Your Own Local MKW Server
#1
Tutorial to Setup Your Own Local MKW Server


In this guide, I will teach you how to setup and run a mkw server whether its for a private use (LAN network) or for public use (anyone around the world can access it). The guide will include methods for both webservers, Apache and Nginx.

Requirements:
Experience with Wii Hacking and ISO Usage (have HBC installed, know how to run codes, etc)
Computer with Linux***
Experience with Linux in general (this isn't for Linux first-timers)

***This guide is specifically for Debian 9! I will include a small modification which should allow this to work on Ubuntu 14.04 LTS & 16.04 LTS.

It is best to start with a fresh installation of Debian 9. I have no idea what packages you already have installed on your Linux computer. They could conflict with the packages being installed on this guide.

Chapter  1. Update, Upgrade, Get Packages

Open a terminal. We need to get Debian fully updated and upgraded before we do anything.


sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade && sudo apt-get autoremove && sudo apt-get autoclean


If upgrades were done, reboot your computer. Now run the following command in terminal to install the necessary packages.


sudo apt-get update && sudo apt-get install ufw apache2 python python-twisted dnsmasq zip unzip



If using nginx replace 'apache2' with 'nginx'.
Small modification for Ubuntu: replace 'python' with 'python-2.7'


Chapter 2. Configuring Firewall, Port Forwarding

The package ufw that was downloaded is a simplified front-end for manipulating Linux's IP-Tables. If you have any current IP-Table firewall settings, clear/flush them now. Be sure to back them up if desired. Run the following terminal commands to get ufw setup with the proper port forwarding


sudo ufw default deny incoming
sudo ufw default allow outgoing


At this point we setup the basic default policies. Do this command now...


sudo ufw allow 80/tcp


There are more ports to open, but we need to test apache/nginx first. To make firewall changes take effect, run the following commands....


sudo ufw enable
sudo ufw status verbose


Your terminal should show on output that the TCP port 80 for both IPv4 and IPv6 is enabled. Let's boot Apache/Nginx now.


sudo service apache2 start


If using nginx, replace 'apache2' with 'nginx'

Open up a web browser. Type in localhost for the web address. You should be greeted by the default Apache Welcome Index Page (or the Nginx default index page if using Nginx).

Ok so Apache/Nginx works, and our firewall is working too. Now we need to punch open more ports. Just use the command that you did earlier for port 80/tcp, and do it for the following ports.

53
443
8000
9000
9001
9002
9003
9009
9998
27500
27900
27901
28910
29900
29901
29920

Alrighty, we're done with TCP ports. But most online gaming servers require the opening of UDP ports. We need all UDP ports opened. So run this command...


sudo ufw allow 2:65535/udp


All UDP ports are now opened. Let's reload the firewall for changes to take effect.


sudo ufw reload


Chapter 3: MKW Server package Download

Go to this link - https://github.com/barronwaffles/dwc_net...r_emulator

Click on the green button that says 'Clone or download'. Click on Download Zip. The MKW server package is now downloaded.

Assuming your downloads go to the folder "/home/yourusername/Downloads", run the following command...


cd /home/yourusername/downloads
unzip dwc_network_server_emulator-master.zip


Or just use any GUI extractor/file-archiver to unzip it.

A folder with the same name as the zip package will appear. Move that folder to a desired place. I personally move it to my main user directory (/home/yourusername). For demo purposes let's assume you move it to that directory.

Chapter 4a: Apache Configuration (skip if using Nginx)


sudo cp /home/yourusername/dwc_network_server_emulator-master/tools/apache-hosts/* /etc/apache2/sites-available


The apache host files have now been copied over to their proper location. We need to make some changes to Apache's config file. Go to /etc/apache2/apache2.conf, and open up that file (with proper sudo permissions) with your preferred text editor.

Scroll all the way to the very bottom and add these two lines...


ServerName localhost

HttpProtocolOptions Unsafe

Save and exit.

Run the following terminal command...


sudo a2ensite


A menu will appear allowing you to select which options you want to enable. Simply enter "*" (without the quotations) and press enter. Apache host files are now enabled.

Now run this command....


sudo a2enmod proxy proxy_http


Apache's Proxy Modules are now enabled. Restart Apache for all your new changes to take effect.


sudo service apache2 restart


Skip Chapter 4b, go to Chapter 5

Chapter 4b: Nginx Configuration (skip if using Apache)

Make a new file called nginx-hosts at the location of /etc/nginx/sites-available

Put the following contents in the nginx-hosts file...

Code:
server {
    listen 80;
    listen [::]:80;
    server_name gamestats.gs.nintendowifi.net gamestats2.gs.nintendowifi.net;
    location / {
        proxy_set_header X-Forwarded-Host $host:$server_port;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:9002;
    }
}

server {
    listen 80;
    listen [::]:80;
    server_name naswii.nintendowifi.net nas.nintendowifi.net conntest.nintendowifi.net;
    location / {    
        proxy_set_header X-Forwarded-Host $host:$server_port;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:9000;
    }
}

server {
    listen 80;
    listen [::]:80;
    server_name sake.gs.nintendowifi.net *.sake.gs.nintendowifi.net secure.sake.gs.nintendowifi.net *.secure.sake.gs.nintendowifi.net;
    location / {
        proxy_set_header X-Forwarded-Host $host:$server_port;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8000;
    }
}

server {
    listen 80;
    listen [::]:80;
    server_name dls1.nintendowifi.net;
    location / {
        proxy_set_header X-Forwarded-Host $host:$server_port;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:9003;
    }
}

Run the following command...


sudo ln -s /etc/nginx/sites-available /etc/nginx/sites-enabled


And now restart nginx...


sudo service nginx restart


Chapter 5. DNSMasq

We need to make some small changes on DNSMasq's config file. Open up the file /etc/dnsmasq.conf usnig proper sudo permissions with your preferred text editor. Scroll down thru the file and look for the following line....


#address=/double-click.net/127.0.0.1


First, you need to remove the '#'. Next change the '127.0.0.1' to your machine's local IP. This is the IP that your internet modem/router assigns to your machine for the lcoal LAN network. This is NOT your public IP. If you don't know the machine's local IP, run this...


hostname -I


If both IPv4 and IPv6 appear, you need the IPv4 (the number that doesn't use colons). For demo purposes, let's say our machine's local IP is 192.168.1.9.

So now the line in the config file would look like this....


address=/double-click.net/192.168.1.9


We're not done yet. Replace double-click.net with nintendowifi.net. So now the line looks like this..


address=/nintendowifi.net/192.168.1.9


Save and exit. Restart DNSMasq for changes to take effect...


sudo service dnsmasq restart


Chapter 6. Admin Page Setup (optional)

This is totally optional. If you don't care to see what your Wiis' Local IP's and MAc Addresses are (w/ ability to ban profiles), then skip to the next chapter.

Make a blank file in the /home/yourusername/dwc_network_server_emulator-master folder called adminpageconf.json Enter in the following contents for adminpageconf.json


{"username":"yourusernamehere","password":"yourpasswordhere"}


yourusernamehere = the username to log in as admin
yourpasswordhere = the password, duh

Do NOT remove the quotations!

Make changes, save and exit.

Chapter 7. First Time Server Boot

Run the following commands.....


sudo service apache2 restart
sudo service dnsmasq restart


If using nginx, replace 'apache2' with 'nginx'.

This is done to make sure all changes to all configurations are enabled. Now do this..


cd /home/yourusername/dwc_network_server_emulator-master
python master_server.py


Once you have pressed enter, the python script will start. Wait about 30 full seconds. This is a first time boot and the storage server can take roughly that time to fully start up.

Alright, the SERVER IS BOOTED!!!

Let's do a quick test now. Open up a web browser and type localhost:9001

This is the Stats page. You can use this page to see how many profiles are online. If you are able to load and see the Stats page then the server is running and it's time for an actual connection test on the Wii.

Chapter 8. Wii Connection Test

Ok we got the computer side-of-things done. Now we need to do some things to the Wii.

Go to Wii Settings, then Internet Settings. Make a brand new connection. Once you have done the connection test and it is complete, go back into the that Connection. Select Change Settings. Scroll left/right until you see 'Auto-Obtain DNS'. Change Yes to No. Click on Advance Settings.

For both Primary and Secondary DNS, enter in your Machine's Local IP address. (The same one you had to enter in for the dnsmasq.conf file from chapter 5)

Save changes, then preform the required Connection Test.

Watch your Linux terminal screen as you do the connection Test. The terminal will spit out some information about receiving a request. Then the Wii should finalize the test and say it is successful. Once successful, exit out of Wii Settings.

Chapter 9.  Connecting to your MKW server

There are a variety of different methods to test the MKW Wifi on your server. For this guide, we will assume you have a clean unmodified ISO/WBFS. Do NOT use any ISOs that have been patched in the past for other servers!!!

Add your clean ISO/WBFS to your USB stick, however you usually do it. Plug USB into Wii. Launch HBC.

If you don't have USB Loader GX (revision 1256 or later), then you can use this cheat code HERE. This code disables the game's SSL connection which is required.

Once you are in USB Loader GX, go to Loader Settings, There is an option for Private Server. Change that to "NoSSL".

Boot your game! You will need to use a fresh license or a license that does NOT have an FC. Make required license.


Go online!!! Watch your Linux terminal screen as you connect online on MKW. A boatload of info will be displayed. After a short time, the info will stop and you will then be online. Congratz! The terminal screen will now do some occasional messages about "keep alive requests". This is normal.

Wink

Chapter 10. Intro to making your MKW server work for public use (anyone can access it)

NOTE to the Noobs: Don't try running this from a computer in your basement, just use a VPS. You can find some for only $3 per month, no hidden fees. Use an 'unmanaged' VPS that allows root access.

You need...
A VPS (virtual private server) already bought for, and it's working. It MUST have an IPv4 address!
A domain name you have already bought (if using the domain name method), that's already been configured to point to your VPS

Chapters 10 and 11 of the guide are not going to baby step every little detail. It's expected that you already have some experience with VPS usage. If you don't know what a VPS is, don't bother trying to do this part of the guide until you know how to purchase one and get it running.

Alright so you got an MKW server to work on the LAN network, now it's time to host it on the world wide web. There are two methods for this: Have users connect with the VPS's public IP, or have them connect via a domain name that points to your VPS.

Chapter 11a. Public IP Method (skip if using Domain Name method)

Simply repeat the steps in this guide from earlier that got your private/LAN MKW server working. However there will be some slight changes plus additions.

On Chapter 2 (Firewall): You will ALSO need to punch open all the TCP and UDP ports on your VPS's firewall. This varies per VPS provider, but just find the settings in your Account page somewhere and open up all the necessary ports.
On Chapter 5 (DNSMasq): Instead of using the private IP of the computer that you were using, you will instead put in your VPS's IPv4 IP.

Reboot (hard reboot) your VPS before launching the MKW server! Process to Chapter 12.

NOTE: Due to some limitations of certain VPS providers, the public IP method might not work even if you did everything correctly.

Chapter 11b. Domain Name Method (skip if using Public IP method)

NOTE: Even though you are doing the domain name method, your VPS still needs an IPv4 address.

Simply repeat the steps in this guide from earlier that got your private/LAN MKW server working.

HOWEVER, skip Chapter 5 entirely (DNSMasq). If you have it already installed from an earlier server install, remove it.

On Chapter 2 (Firewall): You will ALSO need to punch open all the TCP and UDP ports on your VPS's firewall. This varies per VPS provider, but just find the settings in your Account page somewhere and open up all the necessary ports.
On Chapter 4a (apache2 config): In all the files within the apache-hosts folder, replace any instance of 'nintendowifi.net' with your domain name (example: mydomain.com)
On Chapter 4b (nginx config): In the nginx-hosts file, replace any instance of 'nintendowifi.net' with your domain name (example: mydomain.com)

Also, on your VPS, your provider should have a page to edit in DNS names. Add the following DNS names...
Code:
www
nas
naswii
dls1
conntest
*.gs

Reboot (hard reboot) your VPS before launching the MKW server. Please keep in mind that the DNS updates won't take effect for at least 15 minutes on the world wide web.

Chapter 12. Connecting to public MKW Server Online

If using the Public IP method, just repeat how you connected to the LAN MKW server from your Wii, except be sure to now use your VPS's public IP address.
If using the Domain Name method, patch your game using NoSSL code HERE, plus the Domain Full Name Changer code HERE. You won't need the NoSSL code if you are using NoSSL within the USBLoaderGX options.

Regardless of what method you are using, be sure you are testing this with a clean ISO/WBFS!

Try connecting your server. If it fails, view Chapter 13. If it works, congratz!! Big Grin

Chapter 13. Some notes and Troubleshooting

To stop the MKW Server... just exit out of the Terminal Screen. If you are online while you do this, you will receive EC's 84010 or 91010.

To login into the Admin page.. visit localhost:9009 on your web browser.

General Troubleshooting:
Problem: The python script won't run!!!
Answer1: Be sure you have both python and python-twisted installed. Be sure you have configured the proxy for Apache/Nginx correctly. Reboot Apache/Nginx, try again. Apache/Nginx must be running BEFORE you start the script.

Problem: Script has started, but I can't even access the Stats Page!
Answer1: Be sure you have entered in your actual Machine's Local IP correctly on the dnsmasq.conf. Don't just copy what you see posted in this guide. 

Answer2: Instead of typing in localhost:9001 in the web browser, try replacing 'localhost' with your machine's local Ip

Problem: I can't access the Admin Page!
Answer1: Be sure there are no typos in the adminpageconf.json filename. Be sure you didn't accidentally remove any quotations within the file. 

Answer2: Instead of typing in localhost:9009 in the web browser, try replacing 'localhost' with your machine's local Ip

Problem: I keep getting error codes when making a Wii Connection test to the server!
Answer1: Don't forget to edit the Primary/Secondary Addresses. Be sure you didn't typo your Local IP when entering it in too.

Answer2: Did you remember to start the script?

Answer3: Be sure you have opened up all the necessary ports on UFW firewall. Be sure the firewall is running. Reload it to be sure. 

Troubleshooting MKW Specific EC's when connecting online:
20100:
Game was already patched (not clean)
You forgot to set the No SSL options on within USB Loader GX
(If not using USB Loader GX) You forgot to use the NoSSL cheat code
You forgot to enter in the Primary/Secondary DNS IP Addresses (or you made a typo entering them in)
A very very very crappy Internet connection can cause this EC too

234XX:
You forgot to add those small edits needed on the apache2.conf file
You were not on a clean installation of Linux and your apache/nginx configuration already had some files and/or SSL certs installed, so its blocking the connection

23502:
Apache/Nginx is running but the script is not

5XXXX:
Crappy Internet connection, or you forgot to make an Internet connection in Wii Settings

60000:
You used a License with an FC already made on it. Use a brand new License.

84010 & 91010:
The script died or you accidentally closed it


Credits to Polaris!!!! (original python code writer/author for the dwc-network-emulator)
Reply
#2
Will you include a small extra section for (BeanJr's) CoWFC (fork)?
Reply
#3
No, I have no idea about the technical details of CoWFC.
Reply
#4
Thanks for this guide, still works in 2020 on a fresh debian 9 installation. This is just awesome at LAN if you have set up a few Wiis and screens or multviewer.

But however, I had struggles setting up the server... I just couldn't connect the wiis. Solution: I had to install gui for ufw and allow all kinds of traffic. Then it was working just like in the description.

For the next step I wanted to have stats, I went through readmes and scripts, but couldn't find something. is the DWC server emu actually logging pts of the cups/races? this would be so awesome.
Reply
#5
To see the Stats page (it only shows how many profiles are online), go to localhost:9001.
Reply
#6
(05-24-2020, 10:08 PM)Vega Wrote: To see the Stats page (it only shows how many profiles are online), go to localhost:9001.
thanks, yes that is working. for the points I will keep on making screenshots ;-)
Reply
#7
update: this tutorial is working with latest raspbian too. running a Wii-LAN-Rack with dwc on raspberry pi 2
Reply
#8
Is there also a Tutorial for global (with WLAN) MKWii servers reachable for everyone? It would be nice now because AltWFC wants to disable Mario Kart Wii.
Reply
#9
(10-05-2020, 10:18 AM)Unnamed Wrote: Is there also a Tutorial for global (with WLAN) MKWii servers reachable for everyone? It would be nice now because AltWFC wants to disable Mario Kart Wii.

in step 4 replace address=/nintendowifi.net/(local ip) with address=/nintendowifi.net/(public ip) then port forward all of the ports you opened on the server itself
Reply
#10
I built up my own server using cowfc on AWS to play with my friends privately, and i set the domain to the server. but the game gets error code 61010 when connect to the server. anyone can help?
I'm in love clicking the circles, and would screw up the 'white box'
Reply


Forum Jump:


Users browsing this thread: OskarTM, 1 Guest(s)